private boolean isController(InputDevice device) { return ((device.getSources() & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK) && (((device.getSources() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) || (device.getKeyboardType() != InputDevice.KEYBOARD_TYPE_ALPHABETIC)); }
for (int deviceId : deviceIds) { InputDevice dev = InputDevice.getDevice(deviceId); int sources = dev.getSources(); logger.log(Level.FINE, "deviceId[{0}] sources: {1}", new Object[]{deviceId, sources});
InputDevice dev = InputDevice.getDevice(deviceId); int sources = dev.getSources(); // Verify that the device has gamepad buttons, control sticks, or both. if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) && ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) { Log.d(TAG, "device detected : Game Pad"); }
public static boolean isDeviceSDLJoystick(int deviceId) { InputDevice device = InputDevice.getDevice(deviceId); // We cannot use InputDevice.isVirtual before API 16, so let's accept // only nonnegative device ids (VIRTUAL_KEYBOARD equals -1) if ((device == null) || (deviceId < 0)) { return false; } int sources = device.getSources(); /* This is called for every button press, so let's not spam the logs */ /** if ((sources & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK) { Log.v(TAG, "Input device " + device.getName() + " is a joystick."); } if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD) { Log.v(TAG, "Input device " + device.getName() + " is a dpad."); } if ((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) { Log.v(TAG, "Input device " + device.getName() + " is a gamepad."); } **/ return (((sources & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK) || ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD) || ((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) ); }
/** Does the device support a scroll wheel or trackball? */ public static boolean supportsScrollWheel() { int[] ids = InputDevice.getDeviceIds(); for (int id : ids) { InputDevice device = InputDevice.getDevice(id); int sources = device.getSources(); final int sourceTbOrDpad = InputDevice.SOURCE_TRACKBALL | InputDevice.SOURCE_DPAD; if (0 != (sources & sourceTbOrDpad)) return true; } return false; } }
private int getInputDeviceId(int inputSource) { final int DEFAULT_DEVICE_ID = 0; int[] devIds = InputDevice.getDeviceIds(); for (int devId : devIds) { InputDevice inputDev = InputDevice.getDevice(devId); int sources = inputDev.getSources(); // (mSources & source) == source; if ((sources & inputSource) == inputSource) { return devId; } } return DEFAULT_DEVICE_ID; }
public MotionEventSender() { try { Method imInstanceMethod = InputManager.class.getDeclaredMethod("getInstance"); imInstanceMethod.setAccessible(true); inputManager = (InputManager) imInstanceMethod.invoke(null); injectInputEventMethod = InputManager.class.getDeclaredMethod("injectInputEvent", android.view.InputEvent.class, int.class); int[] deviceIds = InputDevice.getDeviceIds(); for (int inputDeviceId : deviceIds) { InputDevice inputDevice = InputDevice.getDevice(inputDeviceId); int deviceSources = inputDevice.getSources(); if ((deviceSources & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) { DEVICE_ID = inputDeviceId; break; } } } catch (Exception e) { e.printStackTrace(); exitFailure(); } }
/** * This method is called by SDL using JNI. * @return an array which may be empty but is never null. */ public static int[] inputGetInputDeviceIds(int sources) { int[] ids = InputDevice.getDeviceIds(); int[] filtered = new int[ids.length]; int used = 0; for (int i = 0; i < ids.length; ++i) { InputDevice device = InputDevice.getDevice(ids[i]); if ((device != null) && ((device.getSources() & sources) != 0)) { filtered[used++] = device.getId(); } } return Arrays.copyOf(filtered, used); }
void findControllersAndAttachShips() { int[] deviceIds = mInputManager.getInputDeviceIds(); for (int deviceId : deviceIds) { InputDevice dev = mInputManager.getInputDevice(deviceId); int sources = dev.getSources(); // if the device is a gamepad/joystick, create a ship to represent it if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) || ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) { // if the device has a gamepad or joystick getShipForId(deviceId); } } }