mirror of
https://github.com/Ryujinx/SDL.git
synced 2024-12-25 13:45:41 +00:00
[Android] Improve handling of keyboard, dpad and gamepad events
Thanks Dimitris Zenios for the report!
This commit is contained in:
parent
45a88b6ade
commit
d37bad52b1
|
@ -600,18 +600,10 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
||||||
@Override
|
@Override
|
||||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||||
// Dispatch the different events depending on where they come from
|
// Dispatch the different events depending on where they come from
|
||||||
if(event.getSource() == InputDevice.SOURCE_KEYBOARD) {
|
// Some SOURCE_DPAD or SOURCE_GAMEPAD events appear to also be marked as SOURCE_KEYBOARD
|
||||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
// So, to avoid problems, we process DPAD or GAMEPAD events first.
|
||||||
//Log.v("SDL", "key down: " + keyCode);
|
|
||||||
SDLActivity.onNativeKeyDown(keyCode);
|
if ( (event.getSource() & 0x00000401) != 0 || /* API 12: SOURCE_GAMEPAD */
|
||||||
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 */
|
|
||||||
(event.getSource() & InputDevice.SOURCE_DPAD) != 0 ) {
|
(event.getSource() & InputDevice.SOURCE_DPAD) != 0 ) {
|
||||||
int id = SDLActivity.getJoyId( event.getDeviceId() );
|
int id = SDLActivity.getJoyId( event.getDeviceId() );
|
||||||
if (id != -1) {
|
if (id != -1) {
|
||||||
|
@ -623,6 +615,18 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
||||||
}
|
}
|
||||||
return true;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue