mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-15 23:40:29 +02:00
Merge pull request #21048 from WalnutTreeDev/androidLeftJoyconFix
Add android fallback when Nintendo Switch Left Joycon keyCode event is 0
This commit is contained in:
1 file changed
+35
@@ -137,12 +137,24 @@ public class InputDeviceState {
|
||||
public boolean onKeyDown(KeyEvent event) {
|
||||
int keyCode = event.getKeyCode();
|
||||
boolean repeat = event.getRepeatCount() > 0;
|
||||
|
||||
if (isInvalidKeyCode(keyCode) && isEventSentByNintendoSwitchLeftJoyCon(event)) {
|
||||
keyCode = remapNintendoSwitchLeftJoyConKeyCodeFromScanCode(event.getScanCode());
|
||||
// need to pass false for the repeat flag, otherwise pressing two adjacent dpad buttons simultaneously to move diagonally does not work.
|
||||
return NativeApp.keyDown(deviceId, keyCode, false);
|
||||
}
|
||||
|
||||
return NativeApp.keyDown(deviceId, keyCode, repeat);
|
||||
}
|
||||
|
||||
// This is called from dispatchKeyEvent.
|
||||
public boolean onKeyUp(KeyEvent event) {
|
||||
int keyCode = event.getKeyCode();
|
||||
|
||||
if (isInvalidKeyCode(keyCode) && isEventSentByNintendoSwitchLeftJoyCon(event)) {
|
||||
keyCode = remapNintendoSwitchLeftJoyConKeyCodeFromScanCode(event.getScanCode());
|
||||
}
|
||||
|
||||
return NativeApp.keyUp(deviceId, keyCode);
|
||||
}
|
||||
|
||||
@@ -166,4 +178,27 @@ public class InputDeviceState {
|
||||
NativeApp.joystickAxis(deviceId, mAxisIds, mValues, count);
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isInvalidKeyCode(int keyCode) {
|
||||
return keyCode == 0;
|
||||
}
|
||||
|
||||
private boolean isEventSentByNintendoSwitchLeftJoyCon(KeyEvent event) {
|
||||
return event.getDevice().getName().contains("Nintendo Switch Left Joy-Con");
|
||||
}
|
||||
|
||||
private int remapNintendoSwitchLeftJoyConKeyCodeFromScanCode(int scanCode) {
|
||||
switch (scanCode) {
|
||||
case 544:
|
||||
return KeyEvent.KEYCODE_DPAD_UP;
|
||||
case 545:
|
||||
return KeyEvent.KEYCODE_DPAD_DOWN;
|
||||
case 546:
|
||||
return KeyEvent.KEYCODE_DPAD_LEFT;
|
||||
case 547:
|
||||
return KeyEvent.KEYCODE_DPAD_RIGHT;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user