當前位置: 首頁>>代碼示例>>Java>>正文


Java InputDevice.SOURCE_KEYBOARD屬性代碼示例

本文整理匯總了Java中android.view.InputDevice.SOURCE_KEYBOARD屬性的典型用法代碼示例。如果您正苦於以下問題:Java InputDevice.SOURCE_KEYBOARD屬性的具體用法?Java InputDevice.SOURCE_KEYBOARD怎麽用?Java InputDevice.SOURCE_KEYBOARD使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.view.InputDevice的用法示例。


在下文中一共展示了InputDevice.SOURCE_KEYBOARD屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendKeyAndWaitForEvent

/**
 * 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;
}
 
開發者ID:MagicHry,項目名稱:EnhancedPUMA,代碼行數:29,代碼來源:MyInteractionController.java

示例2: injectKey

protected void injectKey(int keycode) {
	InputManager inputManager = (InputManager) XposedHelpers
			.callStaticMethod(InputManager.class, "getInstance");
	long now = SystemClock.uptimeMillis();
	final KeyEvent downEvent = new KeyEvent(now, now, KeyEvent.ACTION_DOWN,
			keycode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD,
			0, KeyEvent.FLAG_FROM_SYSTEM, InputDevice.SOURCE_KEYBOARD);
	final KeyEvent upEvent = KeyEvent.changeAction(downEvent,
			KeyEvent.ACTION_UP);

	Integer INJECT_INPUT_EVENT_MODE_ASYNC = XposedHelpers
			.getStaticIntField(InputManager.class,
					"INJECT_INPUT_EVENT_MODE_ASYNC");

	XposedHelpers.callMethod(inputManager, "injectInputEvent", downEvent,
			INJECT_INPUT_EVENT_MODE_ASYNC);
	XposedHelpers.callMethod(inputManager, "injectInputEvent", upEvent,
			INJECT_INPUT_EVENT_MODE_ASYNC);

}
 
開發者ID:adipascu,項目名稱:XposedMenuBeGone,代碼行數:20,代碼來源:Main.java

示例3: sendEvent

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);
    }
}
 
開發者ID:WrBug,項目名稱:GravityBox,代碼行數:15,代碼來源:KeyButtonView.java

示例4: sendKey

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;
}
 
開發者ID:MagicHry,項目名稱:EnhancedPUMA,代碼行數:15,代碼來源:MyInteractionController.java

示例5: sendKeySync

/**
 * 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);
}
 
開發者ID:cuplv,項目名稱:droidel,代碼行數:36,代碼來源:Instrumentation.java

示例6: onKey

@Override
public boolean onKey(View  v, int keyCode, KeyEvent event) {
    // Dispatch the different events depending on where they come from
    // Some SOURCE_JOYSTICK, SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD
    // So, we try to process them as JOYSTICK/DPAD/GAMEPAD events first, if that fails we try them as KEYBOARD
    //
    // Furthermore, it's possible a game controller has SOURCE_KEYBOARD and
    // SOURCE_JOYSTICK, while its key events arrive from the keyboard source
    // So, retrieve the device itself and check all of its sources
    if (SDLActivity.isDeviceSDLJoystick(event.getDeviceId())) {
        // Note that we process events with specific key codes here
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            if (SDLActivity.onNativePadDown(event.getDeviceId(), keyCode) == 0) {
                return true;
            }
        } else if (event.getAction() == KeyEvent.ACTION_UP) {
            if (SDLActivity.onNativePadUp(event.getDeviceId(), keyCode) == 0) {
                return true;
            }
        }
    }

    if ((event.getSource() & InputDevice.SOURCE_KEYBOARD) != 0) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            //Log.v("SDL", "key down: " + keyCode);
            SDLActivity.onNativeKeyDown(keyCode);
            return true;
        }
        else if (event.getAction() == KeyEvent.ACTION_UP) {
            //Log.v("SDL", "key up: " + keyCode);
            SDLActivity.onNativeKeyUp(keyCode);
            return true;
        }
    }

    if ((event.getSource() & InputDevice.SOURCE_MOUSE) != 0) {
        // on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses
        // they are ignored here because sending them as mouse input to SDL is messy
        if ((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_FORWARD)) {
            switch (event.getAction()) {
            case KeyEvent.ACTION_DOWN:
            case KeyEvent.ACTION_UP:
                // mark the event as handled or it will be handled by system
                // handling KEYCODE_BACK by system will call onBackPressed()
                return true;
            }
        }
    }

    return false;
}
 
開發者ID:jomof,項目名稱:cdep-android-studio-freetype-sample,代碼行數:51,代碼來源:SDLActivity.java

示例7: checkUiChoice

/**
 * Check if the input event make us think that user is on TV.
 * If it is the case and if the Ui mode is not setup, then we propose to try the TV UI.
 * @param event
 */
private void checkUiChoice(InputEvent event) {

    // Make sure we go through this method only once
    if (sUiChoiceCheckDone) {
        return;
    }
    sUiChoiceCheckDone = true;

    // No need to check more if this APK does not integrate the leanback UI (this is decided at build time)
    if (!EntryActivity.isLeanbackUiAvailable()) {
        return;
    }

    boolean probablyTv = false;

    switch (event.getSource()) {
        // All these case mean the user is probably on TV
        case InputDevice.SOURCE_KEYBOARD:
        case InputDevice.SOURCE_TOUCHPAD:
        case InputDevice.SOURCE_DPAD:
        case InputDevice.SOURCE_GAMEPAD:
        case InputDevice.SOURCE_JOYSTICK:
        case InputDevice.SOURCE_HDMI:
            Log.d(TAG, "event source = "+event.getSource()+" -> probably TV");
            probablyTv = true;
            break;
        case InputDevice.SOURCE_STYLUS:
        case InputDevice.SOURCE_TOUCHSCREEN:
        case InputDevice.SOURCE_TRACKBALL:
        case InputDevice.SOURCE_MOUSE:
        default:
            Log.d(TAG, "event source = "+event.getSource()+" -> probably not TV");
            probablyTv = false;
            break;
    }

    if (!probablyTv) {
        return;
    }

    final String uiMode = PreferenceManager.getDefaultSharedPreferences(this)
            .getString(UiChoiceDialog.UI_CHOICE_LEANBACK_KEY, "unset");

    // If the choice has not been done yet, ask user
    if (uiMode.equals("unset") &&
         !getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) { // no UI choice to do on actual AndroidTV devices
        new UiChoiceDialog().show(getFragmentManager(), "UiChoiceDialog");
    }
}
 
開發者ID:archos-sa,項目名稱:aos-Video,代碼行數:54,代碼來源:MainActivity.java


注:本文中的android.view.InputDevice.SOURCE_KEYBOARD屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。