protected JoystickButton addButton( int keyCode ) {

//            logger.log(Level.FINE, "Adding button: {0}", keyCode);

            String name = KeyEvent.keyCodeToString(keyCode);
            String original = KeyEvent.keyCodeToString(keyCode);
            // A/B/X/Y buttons
            if (keyCode == KeyEvent.KEYCODE_BUTTON_Y) {
                original = JoystickButton.BUTTON_0;
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_B) {
                original = JoystickButton.BUTTON_1;
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_A) {
                original = JoystickButton.BUTTON_2;
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_X) {
                original = JoystickButton.BUTTON_3;
            // Front buttons  Some of these have the top ones and the bottoms ones flipped.
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_L1) {
                original = JoystickButton.BUTTON_4;
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_R1) {
                original = JoystickButton.BUTTON_5;
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_L2) {
                original = JoystickButton.BUTTON_6;
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_R2) {
                original = JoystickButton.BUTTON_7;
//            // Dpad buttons
//            } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
//                original = JoystickButton.BUTTON_8;
//            } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
//                original = JoystickButton.BUTTON_9;
//            } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
//                original = JoystickButton.BUTTON_8;
//            } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
//                original = JoystickButton.BUTTON_9;
            // Select and start buttons
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_SELECT) {
                original = JoystickButton.BUTTON_8;
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_START) {
                original = JoystickButton.BUTTON_9;
            // Joystick push buttons
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_THUMBL) {
                original = JoystickButton.BUTTON_10;
            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_THUMBR) {
                original = JoystickButton.BUTTON_11;
            }

            String logicalId = JoystickCompatibilityMappings.remapButton( getName(), original );
            if (logger.isLoggable(Level.FINE) && !Objects.equals(logicalId, original)) {
                logger.log(Level.FINE, "Remapped: {0} to: {1}",
                        new Object[]{original, logicalId});
            }

            JoystickButton button = new DefaultJoystickButton( getInputManager(), this, getButtonCount(),
                                                               name, logicalId );
            addButton(button);
            buttonIndex.put( keyCode, button );
            return button;
        }
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