Java Code Examples for android.view.KeyEvent#isGamepadButton()
The following examples show how to use
android.view.KeyEvent#isGamepadButton() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GamepadList.java From 365browser with Apache License 2.0 | 5 votes |
/** * @return True if event's keycode corresponds to a gamepad key. */ public static boolean isGamepadEvent(KeyEvent event) { int keyCode = event.getKeyCode(); switch (keyCode) { // Specific handling for dpad keys is required because // KeyEvent.isGamepadButton doesn't consider dpad keys. case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_LEFT: case KeyEvent.KEYCODE_DPAD_RIGHT: return true; default: return KeyEvent.isGamepadButton(keyCode); } }
Example 2
Source File: MainActivity.java From crazyflie-android-client with GNU General Public License v2.0 | 5 votes |
private static boolean isJoystickButton(int keyCode) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_DPAD_LEFT: case KeyEvent.KEYCODE_DPAD_RIGHT: case KeyEvent.KEYCODE_DPAD_DOWN: return true; default: return KeyEvent.isGamepadButton(keyCode); } }
Example 3
Source File: GameControllerInput.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
private static boolean isGameKey(int keyCode) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_LEFT: case KeyEvent.KEYCODE_DPAD_RIGHT: case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_SPACE: return true; default: return KeyEvent.isGamepadButton(keyCode); } }
Example 4
Source File: AndroidControllers.java From gdx-controllerutils with Apache License 2.0 | 4 votes |
@Override public boolean onKey (View view, int keyCode, KeyEvent keyEvent) { if (ignoreNoGamepadButtons && !keyEvent.isGamepadButton(keyCode)) { return false; } AndroidController controller = controllerMap.get(keyEvent.getDeviceId()); if(controller != null) { if(controller.getButton(keyCode) && keyEvent.getAction() == KeyEvent.ACTION_DOWN) { return true; } synchronized(eventQueue) { AndroidControllerEvent event = eventPool.obtain(); event.controller = controller; if(keyEvent.getAction() == KeyEvent.ACTION_DOWN) { if (keyCode == KeyEvent.KEYCODE_DPAD_UP) { event.type = AndroidControllerEvent.POV; controller.pov |= 0x00000001; event.povDirection = controller.getPov(0); } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { event.type = AndroidControllerEvent.POV; controller.pov |= 0x00000010; event.povDirection = controller.getPov(0); } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) { event.type = AndroidControllerEvent.POV; controller.pov |= 0x00000100; event.povDirection = controller.getPov(0); } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) { event.type = AndroidControllerEvent.POV; controller.pov |= 0x00001000; event.povDirection = controller.getPov(0); } else { event.type = AndroidControllerEvent.BUTTON_DOWN; event.code = keyCode; } } else { if (keyCode == KeyEvent.KEYCODE_DPAD_UP) { event.type = AndroidControllerEvent.POV; controller.pov &= 0x00001110; event.povDirection = controller.getPov(0); } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { event.type = AndroidControllerEvent.POV; controller.pov &= 0x00001101; event.povDirection = controller.getPov(0); } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) { event.type = AndroidControllerEvent.POV; controller.pov &= 0x00001011; event.povDirection = controller.getPov(0); } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) { event.type = AndroidControllerEvent.POV; controller.pov &= 0x00000111; event.povDirection = controller.getPov(0); } else { event.type = AndroidControllerEvent.BUTTON_UP; event.code = keyCode; } } eventQueue.add(event); } if (keyCode == KeyEvent.KEYCODE_BACK && !Gdx.input.isCatchBackKey()) { return false; } return true; } else { return false; } }
Example 5
Source File: GameView.java From codeexamples-android with Eclipse Public License 1.0 | 4 votes |
private static boolean isFireKey(int keyCode) { return KeyEvent.isGamepadButton(keyCode) || keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_SPACE; }
Example 6
Source File: GameView.java From bluetooth with Apache License 2.0 | 2 votes |
/** * Any gamepad button + the spacebar or DPAD_CENTER will be used as the fire * key. * * @param keyCode * @return true of it's a fire key. */ private static boolean isFireKey(int keyCode) { return KeyEvent.isGamepadButton(keyCode) || keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_SPACE; }