private void onMouseClicked(Player player, Mouse button, boolean pressed, int x, int y) {
    PlayerClickEvent event =
        Spout.getEventManager()
            .callEvent(new PlayerClickEvent(player, button, pressed, new IntVector2(x, y)));
    if (event.isCancelled()) {
      return;
    }

    if (Spout.debugMode()) {
      Spout.log("Mouse clicked at {" + x + "," + y + "} was " + (pressed ? "pressed" : "released"));
    }

    Screen s = getInputScreen();
    if (s != null) {
      Widget w = s.getWidgetAt(x, y);
      if (w != null) {
        Widget fw = s.getFocusedWidget();
        if (fw != null && !fw.equals(w)) {
          s.setFocus(w, FocusReason.CLICKED);
        }
        w.onClicked(event);
      }
    }

    executeBindings(getMouseBindingsFor(button), player, pressed);
  }
  private void onMouseMove(Player player, int dx, int dy, int x, int y) {
    // Mouse hasn't moved
    if (dx == 0 && dy == 0) {
      return;
    }

    Screen screen = getInputScreen();
    if (screen != null) {
      IntVector2 prev = new IntVector2(x - dx, y - dy);
      IntVector2 pos = new IntVector2(x, y);
      for (Widget w : screen.getWidgets()) {
        w.onMouseMoved(prev, pos, w == screen.getWidgetAt(x, y));
      }
    }

    // Mouse moved on x-axis
    if (!redirected) {
      if (dx != 0) {
        player.processCommand("dx", new ChatArguments(dx));
      }

      // Mouse moved on y-axis
      if (dy != 0) {
        player.processCommand("dy", new ChatArguments(dy));
      }
    }
  }
  private void onKeyPressed(Player player, Keyboard key, boolean pressed, char ch) {
    final PlayerKeyEvent event =
        Spout.getEventManager().callEvent(new PlayerKeyEvent(player, key, pressed, ch));
    if (event.isCancelled()) {
      return;
    }

    if (Spout.debugMode()) {
      Spout.log("Key " + key + " was " + (pressed ? "pressed" : "released"));
    }

    // SHIFT + TAB changes the focus index
    Screen in = getInputScreen();
    if (key == FOCUS_KEY && pressed) {
      if (in != null) {
        if (org.lwjgl.input.Keyboard.isKeyDown(Keyboard.KEY_LSHIFT.getId())
            || org.lwjgl.input.Keyboard.isKeyDown(Keyboard.KEY_RSHIFT.getId())) {
          in.previousFocus(FocusReason.KEYBOARD_TAB);
        } else {
          in.nextFocus(FocusReason.KEYBOARD_TAB);
        }
      }
    }

    // send event to the focused widget
    if (in != null) {
      Widget w = in.getFocusedWidget();
      if (w != null) {
        w.onKey(event);
      }
    }

    executeBindings(getKeyBindingsFor(key), player, pressed);
  }