public boolean onKey(KeyEvent event) { boolean consumed = false; // logger.log(Level.INFO, "onKey event: {0}", event); event.getDeviceId(); event.getSource(); AndroidJoystick joystick = joystickIndex.get(event.getDeviceId()); if (joystick != null) { JoystickButton button = joystick.getButton(event.getKeyCode()); boolean pressed = event.getAction() == KeyEvent.ACTION_DOWN; if (button != null) { JoyButtonEvent buttonEvent = new JoyButtonEvent(button, pressed); joyInput.addEvent(buttonEvent); consumed = true; } else { JoystickButton newButton = joystick.addButton(event.getKeyCode()); JoyButtonEvent buttonEvent = new JoyButtonEvent(newButton, pressed); joyInput.addEvent(buttonEvent); consumed = true; } } return consumed; }
@Override public void update() { for (final Map.Entry<Integer, GlfwJoystick> entry : joysticks.entrySet()) { // Axes final FloatBuffer axisValues = glfwGetJoystickAxes(entry.getKey()); for (final JoystickAxis axis : entry.getValue().getAxes()) { final float value = axisValues.get(axis.getAxisId()); listener.onJoyAxisEvent(new JoyAxisEvent(axis, value)); } // Buttons final ByteBuffer byteBuffer = glfwGetJoystickButtons(entry.getKey()); for (final JoystickButton button : entry.getValue().getButtons()) { final boolean pressed = byteBuffer.get(button.getButtonId()) == GLFW_PRESS; if (joyButtonPressed.get(button) != pressed) { joyButtonPressed.put(button, pressed); listener.onJoyButtonEvent(new JoyButtonEvent(button, pressed)); } } } }
JoyButtonEvent evt = new JoyButtonEvent(button, e.getValue() == 1f); listener.onJoyButtonEvent(evt);
public void update() { for (final Map.Entry<Integer, GlfwJoystick> entry : joysticks.entrySet()) { // Axes final FloatBuffer axisValues = glfwGetJoystickAxes(entry.getKey()); for (final JoystickAxis axis : entry.getValue().getAxes()) { final float value = axisValues.get(axis.getAxisId()); listener.onJoyAxisEvent(new JoyAxisEvent(axis, value)); } // Buttons final ByteBuffer byteBuffer = glfwGetJoystickButtons(entry.getKey()); for (final JoystickButton button : entry.getValue().getButtons()) { final boolean pressed = byteBuffer.get(button.getButtonId()) == GLFW_PRESS; listener.onJoyButtonEvent(new JoyButtonEvent(button, pressed)); } } }
JoyButtonEvent evt = new JoyButtonEvent(button, e.getValue() == 1f); listener.onJoyButtonEvent(evt);