0

Android provides documentation on how to handle Controller Inputs by attaching event listeners to Views or Activity. But I am interested in simply checking the state of each key without the use of Events. Is that possible?

I am using a generic USB controller, comparable to an XBox controller. Each switch on this controller has a corresponding (keycode, count, and action).

For example: keycode: 196, count: 63, Action: 0,

where they keycode is the identifier, count is how long its been toggled(0 for first press, anything > 0 for long press), and action is the position(0 for off or down position, 1 for on or up position). In that example, I flipped a switch to the down position, and android received 64 events.

I want to be able to poll these states. Something like inputDevice.getKeyState(196), and get the count and action from that. Reason for this is because my android app will sometimes miss events, and Due to the nature of toggle switches, I need to check for the initial toggling of the keys, but ignore any long presses. And on top of that, some of the switch positions don't even produce long pressed events, meaning the count will always be 0, and the event will only fire once.

I have tried looking into the InputDevice class, but cant really get anything from it other than a KeyCharacterMap, and documentation on that is a bit spotty.

I am looking for a solution where if a switch on a controller has a key code of 196, I want to be able to call the inputDevice.getKey(196).getState(), and have it return the position of that switch.

0 Answers0