Java Code Examples for android.view.KeyCharacterMap#VIRTUAL_KEYBOARD

The following examples show how to use android.view.KeyCharacterMap#VIRTUAL_KEYBOARD . 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: InteractionController.java    From za-Farmer with MIT License 6 votes vote down vote up
/**
 * Send keys and blocks until the first specified accessibility event.
 *
 * Most key presses will cause some UI change to occur. If the device is busy, this will
 * block until the device begins to process the key press at which point the call returns
 * and normal wait for idle processing may begin. If no events are detected for the
 * timeout period specified, the call will return anyway with false.
 *
 * @param keyCode
 * @param metaState
 * @param eventType
 * @param timeout
 * @return true if events is received, otherwise false.
 */
public boolean sendKeyAndWaitForEvent(final int keyCode, final int metaState,
        final int eventType, long timeout) {
    Runnable command = new Runnable() {
        @Override
        public void run() {
            final long eventTime = SystemClock.uptimeMillis();
            KeyEvent downEvent = new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN,
                    keyCode, 0, metaState, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0,
                    InputDevice.SOURCE_KEYBOARD);
            if (injectEventSync(downEvent)) {
                KeyEvent upEvent = new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_UP,
                        keyCode, 0, metaState, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0,
                        InputDevice.SOURCE_KEYBOARD);
                injectEventSync(upEvent);
            }
        }
    };

    return runAndWaitForEvents(command, new WaitForAnyEventPredicate(eventType), timeout)
            != null;
}
 
Example 2
Source File: InteractionController.java    From za-Farmer with MIT License 6 votes vote down vote up
public boolean sendKey(int keyCode, int metaState) {
    if (DEBUG) {
        Log.d(LOG_TAG, "sendKey (" + keyCode + ", " + metaState + ")");
    }

    final long eventTime = SystemClock.uptimeMillis();
    KeyEvent downEvent = new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN,
            keyCode, 0, metaState, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0,
            InputDevice.SOURCE_KEYBOARD);
    if (injectEventSync(downEvent)) {
        KeyEvent upEvent = new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_UP,
                keyCode, 0, metaState, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0,
                InputDevice.SOURCE_KEYBOARD);
        if(injectEventSync(upEvent)) {
            return true;
        }
    }
    return false;
}
 
Example 3
Source File: InteractionController.java    From JsDroidCmd with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Send keys and blocks until the first specified accessibility event.
 * 
 * Most key presses will cause some UI change to occur. If the device is
 * busy, this will block until the device begins to process the key press at
 * which point the call returns and normal wait for idle processing may
 * begin. If no events are detected for the timeout period specified, the
 * call will return anyway with false.
 * 
 * @param keyCode
 * @param metaState
 * @param eventType
 * @param timeout
 * @return true if events is received, otherwise false.
 */
public boolean sendKeyAndWaitForEvent(final int keyCode,
		final int metaState, final int eventType, long timeout) {
	Runnable command = new Runnable() {
		@Override
		public void run() {
			final long eventTime = SystemClock.uptimeMillis();
			KeyEvent downEvent = new KeyEvent(eventTime, eventTime,
					KeyEvent.ACTION_DOWN, keyCode, 0, metaState,
					KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0,
					InputDevice.SOURCE_KEYBOARD);
			if (injectEventSync(downEvent)) {
				KeyEvent upEvent = new KeyEvent(eventTime, eventTime,
						KeyEvent.ACTION_UP, keyCode, 0, metaState,
						KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0,
						InputDevice.SOURCE_KEYBOARD);
				injectEventSync(upEvent);
			}
		}
	};

	return runAndWaitForEvents(command, new WaitForAnyEventPredicate(
			eventType), timeout) != null;
}
 
Example 4
Source File: InteractionController.java    From JsDroidCmd with Mozilla Public License 2.0 6 votes vote down vote up
public boolean sendKey(int keyCode, int metaState) {
	if (DEBUG) {
		Log.d(LOG_TAG, "sendKey (" + keyCode + ", " + metaState + ")");
	}

	final long eventTime = SystemClock.uptimeMillis();
	KeyEvent downEvent = new KeyEvent(eventTime, eventTime,
			KeyEvent.ACTION_DOWN, keyCode, 0, metaState,
			KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0,
			InputDevice.SOURCE_KEYBOARD);
	if (injectEventSync(downEvent)) {
		KeyEvent upEvent = new KeyEvent(eventTime, eventTime,
				KeyEvent.ACTION_UP, keyCode, 0, metaState,
				KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0,
				InputDevice.SOURCE_KEYBOARD);
		if (injectEventSync(upEvent)) {
			return true;
		}
	}
	return false;
}
 
Example 5
Source File: MyInteractionController.java    From PUMA with Apache License 2.0 6 votes vote down vote up
/**
 * Send keys and blocks until the first specified accessibility event.
 *
 * Most key presses will cause some UI change to occur. If the device is busy, this will
 * block until the device begins to process the key press at which point the call returns
 * and normal wait for idle processing may begin. If no events are detected for the
 * timeout period specified, the call will return anyway with false.
 *
 * @param keyCode
 * @param metaState
 * @param eventType
 * @param timeout
 * @return true if events is received, otherwise false.
 */
public boolean sendKeyAndWaitForEvent(final int keyCode, final int metaState, final int eventType, long timeout) {
	Runnable command = new Runnable() {
		@Override
		public void run() {
			final long eventTime = SystemClock.uptimeMillis();
			KeyEvent downEvent = new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN, keyCode, 0, metaState, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD);
			if (injectEventSync(downEvent)) {
				KeyEvent upEvent = new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_UP, keyCode, 0, metaState, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD);
				injectEventSync(upEvent);
			}
		}
	};

	return runAndWaitForEvents(command, new WaitForAnyEventPredicate(eventType), timeout) != null;
}
 
Example 6
Source File: BaseInputConnection.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void sendCurrentText() {
    if (!mDummyMode) {
        return;
    }

    Editable content = getEditable();
    if (content != null) {
        final int N = content.length();
        if (N == 0) {
            return;
        }
        if (N == 1) {
            // If it's 1 character, we have a chance of being
            // able to generate normal key events...
            if (mKeyCharacterMap == null) {
                mKeyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
            }
            char[] chars = new char[1];
            content.getChars(0, 1, chars, 0);
            KeyEvent[] events = mKeyCharacterMap.getEvents(chars);
            if (events != null) {
                for (int i=0; i<events.length; i++) {
                    if (DEBUG) Log.v(TAG, "Sending: " + events[i]);
                    sendKeyEvent(events[i]);
                }
                content.clear();
                return;
            }
        }

        // Otherwise, revert to the special key event containing
        // the actual characters.
        KeyEvent event = new KeyEvent(SystemClock.uptimeMillis(),
                content.toString(), KeyCharacterMap.VIRTUAL_KEYBOARD, 0);
        sendKeyEvent(event);
        content.clear();
    }
}
 
Example 7
Source File: KeyButtonView.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
void sendEvent(int action, int flags, long when, boolean applyDefaultFlags) {
    try {
        final int repeatCount = (flags & KeyEvent.FLAG_LONG_PRESS) != 0 ? 1 : 0;
        if (applyDefaultFlags) {
            flags |= KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY;
        }
        final KeyEvent ev = new KeyEvent(mDownTime, when, action, mCode, repeatCount,
                0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags,
                InputDevice.SOURCE_KEYBOARD);
        final Object inputManager = XposedHelpers.callStaticMethod(InputManager.class, "getInstance");
        XposedHelpers.callMethod(inputManager, "injectInputEvent", ev, 0);
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
 
Example 8
Source File: MyInteractionController.java    From PUMA with Apache License 2.0 5 votes vote down vote up
public boolean sendKey(int keyCode, int metaState) {
	if (DEBUG) {
		Log.d(LOG_TAG, "sendKey (" + keyCode + ", " + metaState + ")");
	}

	final long eventTime = SystemClock.uptimeMillis();
	KeyEvent downEvent = new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN, keyCode, 0, metaState, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD);
	if (injectEventSync(downEvent)) {
		KeyEvent upEvent = new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_UP, keyCode, 0, metaState, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD);
		if (injectEventSync(upEvent)) {
			return true;
		}
	}
	return false;
}