本文整理汇总了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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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);
}
示例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;
}
示例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");
}
}