-
-
Save michael-conrad/8aab9eb32f63e4becdcd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Key events | |
| @Override | |
| public boolean onKey(View v, int keyCode, KeyEvent event) { | |
| // Dispatch the different events depending on where they come from | |
| // Some SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD | |
| // So, we try to process them as DPAD or GAMEPAD events first, if that fails we try them as KEYBOARD | |
| if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { | |
| keyCode = KeyEvent.KEYCODE_ENTER; | |
| } | |
| if (event.getAction() == KeyEvent.ACTION_DOWN) { | |
| //Log.v("SDL", "key down: " + keyCode); | |
| SDLActivity.onNativeKeyDown(keyCode); | |
| return true; | |
| } | |
| if (event.getAction() == KeyEvent.ACTION_UP) { | |
| //Log.v("SDL", "key up: " + keyCode); | |
| SDLActivity.onNativeKeyUp(keyCode); | |
| return true; | |
| } | |
| if (true) { | |
| return false; | |
| } | |
| // Dispatch the different events depending on where they come from | |
| // Some SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD | |
| // So, we try to process them as DPAD or GAMEPAD events first, if that fails we try them as KEYBOARD | |
| if ( (event.getSource() & 0x00000401) != 0 || /* API 12: SOURCE_GAMEPAD */ | |
| (event.getSource() & InputDevice.SOURCE_DPAD) != 0 ) { | |
| if (event.getAction() == KeyEvent.ACTION_DOWN) { | |
| if (SDLActivity.onNativePadDown(event.getDeviceId(), keyCode) == 0) { | |
| return true; | |
| } | |
| } else if (event.getAction() == KeyEvent.ACTION_UP) { | |
| if (SDLActivity.onNativePadUp(event.getDeviceId(), keyCode) == 0) { | |
| return true; | |
| } | |
| } | |
| } | |
| 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; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment