Generic gamepad not working on Android

Hello,

The gamepad works fine on Linux, but doesn’t work on Android, the gamepad on Android generates the keys AKEYCODE_BUTTON_1 to AKEYCODE_BUTTON_16, i tried to print the action_id but the return is “hash:[1725367350475554478 (unknown)]”, the numbers in the hash change for each button pressed.

Printing hashes always gives that in release mode bundles. I don’t know why it’s generating those keys instead of something like AKEYCODE_BUTTON_A or AKEYCODE_DPAD_LEFT, but running a debug mode bundle should correctly print out action_id and give some clues.

2 Likes

I tested with a mouse and the action_id gives the right hash.

On Linux or Android?

Android

Seems like a bug if only certain hashes can be reversed. Also, your gamepad should be outputting these keycodes instead of the generic AKEYCODE_BUTTON_##. My guess is that your controller is weird and Defold doesn’t know what to do about it. Maybe someone more experienced with controllers and Android has more ideas?

1 Like

I almost sure the gamepad isn’t working because the defold doesn’t supports theses AKEYCODE_BUTTON_##, i think if put theses AKEYCODE_BUTTON_## here could work.

Each gamepad needs an entry in the gamepad file per platform. Just because you have an entry for Linux for instance doesn’t mean you have one for Android. The mapping from Android keycode to Defold gamepad mapping can be seen here: Gamepad input in Defold

You can use this to test the gamepad and get its mapping info https://play.google.com/store/apps/details?id=ru.elron.gamepadtester&hl=en&gl=US

I have an entry for Android too, maybe i did it wrong, tomorrow i will check it out.

I tested the gamepad with this app and the key codes returns from 188 to 203.

Interesting. It’s AKEYCODE_BUTTON_1 through AKEYCODE_BUTTON_16:

https://developer.android.com/ndk/reference/group/input#group___input_1ggafccd240f973cf154952fb917c9209719a28c72c33ab93d83539d0790b7e48336a

As you can see neither of those keycodes are covered in the current implementation of the Android gamepad support in Defold. It is quite surprising that you’re not getting the standardised keycodes for gamepads as documented here:

How do those 1-16 buttons translate to the standard gamepad configuration? Which button is 1, which is 2 and so on?

I couldn’t find the Lpad key code, maybe is KEYCODE_DPAD_UP ,KEYCODE_DPAD_DOWN , KEYCODE_DPAD_LEFT , KEYCODE_DPAD_RIGHT?
188 = RpadUp,
189 = RpadRight,
190 = RpadDown,
191 = RpadLeft,
192 = Lshoulder,
193 = Rshoulder,
194 = Ltrigger,
195 = Rtrigger,
196 = Back,
197 = Start,
198 = Lstick click,
199 = Rstick click,

the app doesn’t show the name of the axis, i guess that is AMOTION_EVENT_AXIS_X, AMOTION_EVENT_AXIS_Y, AMOTION_EVENT_AXIS_RZ.

AXIS_X : -1.0 = Lstick left,
AXIS_X: 1.0 = Lstick right,
AXIS_Y: -1.0 = Lstick up,
AXIS_Y: 1.0 = Lstick down,
AXIS_Z: -1.0 = Rstick left,
AXIS_Z: 1.0 = Rstick right,
AXIS_RZ: -1.0 = Rstick up,
AXIS_RZ: 1.0 = Rstick down.

2 Likes

The gamepad return the keys 188 to 199(previously i said 188 to 203, i was wrong, sorry) but i have an interface from an arcade machine that returns the keys 188 to 203, the keys doesn’t have a name, so can you add this too? because the gamepad only have 12 buttons and the arcade’s interface uses 16 buttons. The names of the buttons could be like: generic button 1 … generic button 16.

Could you please try with this app: https://play.google.com/store/apps/details?id=ru.elron.gamepadtester

And share some screenshots of the outcome! Thanks.


Thank you. We need to think about how to deal with gamepads such as this one that doesn’t map to the “standard” gamepad buttons.

1 Like

Okay, thank you.

I’ve created a ticket to track this feature request: Support additional Android gamepad keycodes · Issue #5965 · defold/defold · GitHub

1 Like

The latest Defold beta (1.2.186) contains support for mapping button 1 to 16:

The new version also supports unidentified gamepads through a raw gamepad data binding:

Unidentified: Gamepad input in Defold
Raw: Gamepad input in Defold

3 Likes