Skip to content

Commit

Permalink
[Android] Improve handling of keyboard, dpad and gamepad events
Browse files Browse the repository at this point in the history
Thanks Dimitris Zenios for the report!
  • Loading branch information
gabomdq committed Nov 11, 2013
1 parent 45a88b6 commit d37bad5
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions android-project/src/org/libsdl/app/SDLActivity.java
Expand Up @@ -600,18 +600,10 @@ public void onDraw(Canvas canvas) {}
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// Dispatch the different events depending on where they come from
if(event.getSource() == InputDevice.SOURCE_KEYBOARD) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
//Log.v("SDL", "key down: " + keyCode);
SDLActivity.onNativeKeyDown(keyCode);
return true;
}
else if (event.getAction() == KeyEvent.ACTION_UP) {
//Log.v("SDL", "key up: " + keyCode);
SDLActivity.onNativeKeyUp(keyCode);
return true;
}
} else if ( (event.getSource() & 0x00000401) != 0 || /* API 12: SOURCE_GAMEPAD */
// Some SOURCE_DPAD or SOURCE_GAMEPAD events appear to also be marked as SOURCE_KEYBOARD
// So, to avoid problems, we process DPAD or GAMEPAD events first.

if ( (event.getSource() & 0x00000401) != 0 || /* API 12: SOURCE_GAMEPAD */
(event.getSource() & InputDevice.SOURCE_DPAD) != 0 ) {
int id = SDLActivity.getJoyId( event.getDeviceId() );
if (id != -1) {
Expand All @@ -623,6 +615,18 @@ else if (event.getAction() == KeyEvent.ACTION_UP) {
}
return true;
}
else if( (event.getSource() & InputDevice.SOURCE_KEYBOARD) != 0) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
//Log.v("SDL", "key down: " + keyCode);
SDLActivity.onNativeKeyDown(keyCode);
return true;
}
else if (event.getAction() == KeyEvent.ACTION_UP) {
//Log.v("SDL", "key up: " + keyCode);
SDLActivity.onNativeKeyUp(keyCode);
return true;
}
}

return false;
}
Expand Down

0 comments on commit d37bad5

Please sign in to comment.