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;
    }
Main class that creates and manages Android inputs for physical gamepads/joysticks.

@author iwgeric
jme3-android/src/main/java/com/jme3/input/android/AndroidJoystickJoyInput14.java