Java Code Examples for android.view.KeyEvent#getSource()
The following examples show how to use
android.view.KeyEvent#getSource() .
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: Instrumentation.java From AndroidComponentPlugin with Apache License 2.0 | 6 votes |
/** * Send a key event to the currently focused window/view and wait for it to * be processed. Finished at some point after the recipient has returned * from its event processing, though it may <em>not</em> have completely * finished reacting from the event -- for example, if it needs to update * its display as a result, it may still be in the process of doing that. * * @param event The event to send to the current focus. */ public void sendKeySync(KeyEvent event) { validateNotAppThread(); long downTime = event.getDownTime(); long eventTime = event.getEventTime(); int source = event.getSource(); if (source == InputDevice.SOURCE_UNKNOWN) { source = InputDevice.SOURCE_KEYBOARD; } if (eventTime == 0) { eventTime = SystemClock.uptimeMillis(); } if (downTime == 0) { downTime = eventTime; } KeyEvent newEvent = new KeyEvent(event); newEvent.setTime(downTime, eventTime); newEvent.setSource(source); newEvent.setFlags(event.getFlags() | KeyEvent.FLAG_FROM_SYSTEM); InputManager.getInstance().injectInputEvent(newEvent, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH); }
Example 2
Source File: AndroidInputHandler.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public boolean onKey(View view, int keyCode, KeyEvent event) { if (view != getView()) { return false; } boolean consumed = false; int source = event.getSource(); // logger.log(Level.INFO, "onKey source: {0}", source); boolean isTouch = ((source & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) || ((source & InputDevice.SOURCE_KEYBOARD) == InputDevice.SOURCE_KEYBOARD); // logger.log(Level.INFO, "onKey source: {0}, isTouch: {1}", // new Object[]{source, isTouch}); if (touchInput != null) { consumed = touchInput.onKey(event); } return consumed; }
Example 3
Source File: Gamepad.java From BobEngine with GNU Lesser General Public License v2.1 | 6 votes |
@TargetApi(19) public boolean onKeyDown(int keyCode, KeyEvent event) { int player; // The player number (controller number) that caused this event if (event.getDevice() != null && (event.getSource() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) { try { player = event.getDevice().getControllerNumber(); } catch (NoSuchMethodError e) { player = 1; } if (event.getRepeatCount() == 0 || player != lastPlayerDown) { newpress(player, keyCode); lastPlayerDown = player; } return true; } return false; }
Example 4
Source File: Gamepad.java From BobEngine with GNU Lesser General Public License v2.1 | 6 votes |
@TargetApi(19) public boolean onKeyUp(int keyCode, KeyEvent event) { int player; // The player number (controller number) that caused this event if (event.getDevice() != null && (event.getSource() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) { try { player = event.getDevice().getControllerNumber(); } catch (NoSuchMethodError e) { player = 1; } if (event.getRepeatCount() == 0 || player != lastPlayerUp) { released(player, keyCode); lastPlayerUp = player; } return true; } return false; }
Example 5
Source File: Instrumentation.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
/** * Send a key event to the currently focused window/view and wait for it to * be processed. Finished at some point after the recipient has returned * from its event processing, though it may <em>not</em> have completely * finished reacting from the event -- for example, if it needs to update * its display as a result, it may still be in the process of doing that. * * @param event The event to send to the current focus. */ public void sendKeySync(KeyEvent event) { validateNotAppThread(); long downTime = event.getDownTime(); long eventTime = event.getEventTime(); int action = event.getAction(); int code = event.getKeyCode(); int repeatCount = event.getRepeatCount(); int metaState = event.getMetaState(); int deviceId = event.getDeviceId(); int scancode = event.getScanCode(); int source = event.getSource(); int flags = event.getFlags(); if (source == InputDevice.SOURCE_UNKNOWN) { source = InputDevice.SOURCE_KEYBOARD; } if (eventTime == 0) { eventTime = SystemClock.uptimeMillis(); } if (downTime == 0) { downTime = eventTime; } KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source); InputManager.getInstance().injectInputEvent(newEvent, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH); }
Example 6
Source File: Instrumentation.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
/** * Send a key event to the currently focused window/view and wait for it to * be processed. Finished at some point after the recipient has returned * from its event processing, though it may <em>not</em> have completely * finished reacting from the event -- for example, if it needs to update * its display as a result, it may still be in the process of doing that. * * @param event The event to send to the current focus. */ public void sendKeySync(KeyEvent event) { validateNotAppThread(); long downTime = event.getDownTime(); long eventTime = event.getEventTime(); int action = event.getAction(); int code = event.getKeyCode(); int repeatCount = event.getRepeatCount(); int metaState = event.getMetaState(); int deviceId = event.getDeviceId(); int scancode = event.getScanCode(); int source = event.getSource(); int flags = event.getFlags(); if (source == InputDevice.SOURCE_UNKNOWN) { source = InputDevice.SOURCE_KEYBOARD; } if (eventTime == 0) { eventTime = SystemClock.uptimeMillis(); } if (downTime == 0) { downTime = eventTime; } KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source); InputManager.getInstance().injectInputEvent(newEvent, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH); }
Example 7
Source File: Instrumentation.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Send a key event to the currently focused window/view and wait for it to * be processed. Finished at some point after the recipient has returned * from its event processing, though it may <em>not</em> have completely * finished reacting from the event -- for example, if it needs to update * its display as a result, it may still be in the process of doing that. * * @param event The event to send to the current focus. */ public void sendKeySync(KeyEvent event) { validateNotAppThread(); long downTime = event.getDownTime(); long eventTime = event.getEventTime(); int action = event.getAction(); int code = event.getKeyCode(); int repeatCount = event.getRepeatCount(); int metaState = event.getMetaState(); int deviceId = event.getDeviceId(); int scancode = event.getScanCode(); int source = event.getSource(); int flags = event.getFlags(); if (source == InputDevice.SOURCE_UNKNOWN) { source = InputDevice.SOURCE_KEYBOARD; } if (eventTime == 0) { eventTime = SystemClock.uptimeMillis(); } if (downTime == 0) { downTime = eventTime; } KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source); InputManager.getInstance().injectInputEvent(newEvent, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH); }
Example 8
Source File: InputHelper.java From XposedSmsCode with GNU General Public License v3.0 | 5 votes |
/** * refer: com.android.commands.input.Input#sendText() * * @throws Throwable throwable throws if the caller has no android.permission.INJECT_EVENTS permission */ public static void sendText(String text) throws Throwable { int source = InputDevice.SOURCE_KEYBOARD; StringBuilder sb = new StringBuilder(text); boolean escapeFlag = false; for (int i = 0; i < sb.length(); i++) { if (escapeFlag) { escapeFlag = false; if (sb.charAt(i) == 's') { sb.setCharAt(i, ' '); sb.deleteCharAt(--i); } } if (sb.charAt(i) == '%') { escapeFlag = true; } } char[] chars = sb.toString().toCharArray(); KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD); KeyEvent[] events = kcm.getEvents(chars); for (KeyEvent keyEvent : events) { if (source != keyEvent.getSource()) { keyEvent.setSource(source); } injectKeyEvent(keyEvent); } }
Example 9
Source File: Instrumentation.java From droidel with Apache License 2.0 | 5 votes |
/** * Send a key event to the currently focused window/view and wait for it to * be processed. Finished at some point after the recipient has returned * from its event processing, though it may <em>not</em> have completely * finished reacting from the event -- for example, if it needs to update * its display as a result, it may still be in the process of doing that. * * @param event The event to send to the current focus. */ public void sendKeySync(KeyEvent event) { validateNotAppThread(); long downTime = event.getDownTime(); long eventTime = event.getEventTime(); int action = event.getAction(); int code = event.getKeyCode(); int repeatCount = event.getRepeatCount(); int metaState = event.getMetaState(); int deviceId = event.getDeviceId(); int scancode = event.getScanCode(); int source = event.getSource(); int flags = event.getFlags(); if (source == InputDevice.SOURCE_UNKNOWN) { source = InputDevice.SOURCE_KEYBOARD; } if (eventTime == 0) { eventTime = SystemClock.uptimeMillis(); } if (downTime == 0) { downTime = eventTime; } KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source); InputManager.getInstance().injectInputEvent(newEvent, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH); }
Example 10
Source File: AndroidInputHandler14.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public boolean onKey(View view, int keyCode, KeyEvent event) { if (view != getView()) { return false; } boolean consumed = false; // logger.log(Level.INFO, "onKey keyCode: {0}, action: {1}, event: {2}", // new Object[]{KeyEvent.keyCodeToString(keyCode), event.getAction(), event}); int source = event.getSource(); // logger.log(Level.INFO, "onKey source: {0}", source); boolean isTouch = ((source & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) || ((source & InputDevice.SOURCE_KEYBOARD) == InputDevice.SOURCE_KEYBOARD); boolean isJoystick = ((source & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) || ((source & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK); boolean isUnknown = (source & android.view.InputDevice.SOURCE_UNKNOWN) == android.view.InputDevice.SOURCE_UNKNOWN; if (touchInput != null && (isTouch || (isUnknown && this.touchInput.isSimulateKeyboard()))) { // logger.log(Level.INFO, "onKey source: {0}, isTouch: {1}", // new Object[]{source, isTouch}); consumed = touchInput.onKey(event); } if (isJoystick && joyInput != null) { // logger.log(Level.INFO, "onKey source: {0}, isJoystick: {1}", // new Object[]{source, isJoystick}); // use inclusive OR to make sure the onKey method is called. consumed = consumed | ((AndroidJoyInput14)joyInput).onKey(event); } return consumed; }