Search code examples
javaandroidonkeydownonkeyup

Android physical keyboard support for key press and hold


I am trying to prepare my game for Google Play Games on PC (my game being added in February). Currently, movement in my Android game client is handled by an onscreen joystick. You can tap to move one tile or hold to move until you release. I am trying to code WASD keyboard movement in a similar manner.

The Android onKeyDown and onKeyUp works for single key presses, but the event.startTracking() method and onKeyLongPress does not seem to work for physical keyboards (example code: https://stackoverflow.com/a/18799434/572286). When I press and hold a keyboard key (i.e. W) it just fires onKeyDown/onKeyUp repeadetly.

enter image description here

Does anyone have any ideas here? I have scoured StackOVerflow and Google and am coming up empty. This is driving me crazy.

Seems like this is slightly related, though this person did not go beyond onKeyDown/onKeyUp to startTracking/onKeyLongPress: Android: how to detect keyboard press and release events?


Solution

  • Thank you @CommonsWare for the help! Per the link he shared: https://issuetracker.google.com/issues/269765408

    "Studio Hedgehog Canary 15 will have the "Hardware Input" mode that will send individual key down and key up events just as they come from the host keyboard. This mode will be controlled by a toolbar button."

    AKA click this button below. Works like a charm now.

    enter image description here