diff --git a/android/src/org/ppsspp/ppsspp/InputDeviceState.java b/android/src/org/ppsspp/ppsspp/InputDeviceState.java index 89e9d0f016..2e1123dbad 100644 --- a/android/src/org/ppsspp/ppsspp/InputDeviceState.java +++ b/android/src/org/ppsspp/ppsspp/InputDeviceState.java @@ -12,7 +12,7 @@ import android.view.MotionEvent; public class InputDeviceState { private static final String TAG = "InputDeviceState"; - private static final int deviceId = NativeApp.DEVICE_ID_PAD_0; + public static final int deviceId = NativeApp.DEVICE_ID_PAD_0; private InputDevice mDevice; private int[] mAxes; diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index 6a1b82bf67..be31512fed 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -912,7 +912,6 @@ public abstract class NativeActivity extends Activity { } } - // We simply grab the first input device to produce an event and ignore all others that are connected. @TargetApi(Build.VERSION_CODES.GINGERBREAD) private InputDeviceState getInputDeviceState(InputEvent event) { InputDevice device = event.getDevice(); @@ -967,24 +966,29 @@ public abstract class NativeActivity extends Activity { // Let's let back and menu through to dispatchKeyEvent. boolean passThrough = false; + int sources = event.getSource(); + switch (event.getKeyCode()) { case KeyEvent.KEYCODE_BACK: case KeyEvent.KEYCODE_MENU: passThrough = true; + Log.i(TAG, "Passing through key, source = " + sources); break; default: break; } - // Don't passthrough back button if gamepad. - int sources = event.getSource(); - switch (sources) { - case InputDevice.SOURCE_GAMEPAD: - case InputDevice.SOURCE_JOYSTICK: - case InputDevice.SOURCE_DPAD: + // Don't passthrough back or menu button if from gamepad. + // XInput device on Android returns source 1281 or 0x501, which equals GAMEPAD | KEYBOARD. + // Shield Remote returns 769 or 0x301 which equals DPAD | KEYBOARD. + + if ((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD || + (sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK || + (sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD) + { passThrough = false; - break; } + Log.i(TAG, "Input event device sources: " + sources); if (!passThrough) { switch (event.getAction()) { @@ -1058,18 +1062,18 @@ public abstract class NativeActivity extends Activity { switch (keyCode) { case KeyEvent.KEYCODE_BACK: if (event.isAltPressed()) { - NativeApp.keyDown(0, 1004, repeat); // special custom keycode for the O button on Xperia Play + NativeApp.keyDown(InputDeviceState.deviceId, 1004, repeat); // special custom keycode for the O button on Xperia Play } else if (NativeApp.isAtTopLevel()) { - Log.i(TAG, "IsAtTopLevel returned true."); + Log.i(TAG, "IsAtTopLevel returned true."); // Pass through the back event. return super.onKeyDown(keyCode, event); } else { - NativeApp.keyDown(0, keyCode, repeat); + NativeApp.keyDown(InputDeviceState.deviceId, keyCode, repeat); } return true; case KeyEvent.KEYCODE_MENU: case KeyEvent.KEYCODE_SEARCH: - NativeApp.keyDown(0, keyCode, repeat); + NativeApp.keyDown(InputDeviceState.deviceId, keyCode, repeat); return true; case KeyEvent.KEYCODE_DPAD_UP: @@ -1078,6 +1082,7 @@ public abstract class NativeActivity extends Activity { case KeyEvent.KEYCODE_DPAD_RIGHT: // Joysticks are supported in Honeycomb MR1 and later via the onGenericMotionEvent method. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1 && event.getSource() == InputDevice.SOURCE_JOYSTICK) { + // Pass through / ignore return super.onKeyDown(keyCode, event); } // Fall through @@ -1085,7 +1090,7 @@ public abstract class NativeActivity extends Activity { // send the rest of the keys through. // TODO: get rid of the three special cases above by adjusting the native side of the code. // Log.d(TAG, "Key down: " + keyCode + ", KeyEvent: " + event); - return NativeApp.keyDown(0, keyCode, repeat); + return NativeApp.keyDown(InputDeviceState.deviceId, keyCode, repeat); } }