android.view.KeyEvent.getDevice()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(4.1k)|赞(0)|评价(0)|浏览(317)

本文整理了Java中android.view.KeyEvent.getDevice()方法的一些代码示例,展示了KeyEvent.getDevice()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。KeyEvent.getDevice()方法的具体详情如下:
包路径:android.view.KeyEvent
类名称:KeyEvent
方法名:getDevice

KeyEvent.getDevice介绍

暂无

代码示例

代码示例来源:origin: termux/termux-app

/** Handle dedicated volume buttons as virtual keys if applicable. */
private boolean handleVirtualKeys(int keyCode, KeyEvent event, boolean down) {
  InputDevice inputDevice = event.getDevice();
  if (inputDevice != null && inputDevice.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
    // Do not steal dedicated buttons from a full external keyboard.
    return false;
  } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
    mVirtualControlKeyDown = down;
    return true;
  } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
    mVirtualFnKeyDown = down;
    return true;
  }
  return false;
}

代码示例来源:origin: robolectric/robolectric

@Test
 public void canSetInputDeviceOnKeyEvent() throws Exception {
  InputDevice myDevice = ShadowInputDevice.makeInputDeviceNamed("myDevice");
  KeyEvent keyEvent = new KeyEvent(1, 2);
  shadowOf(keyEvent).setDevice(myDevice);
  assertThat(keyEvent.getDevice().getName()).isEqualTo("myDevice");
 }
}

代码示例来源:origin: czhzero/scangon

/**
 * 是否为扫码枪事件(部分机型KeyEvent获取的名字错误)
 * @param event
 * @return
 */
@Deprecated
public boolean isScanGunEvent(KeyEvent event) {
  return event.getDevice().getName().equals(mDeviceName);
}

代码示例来源:origin: CypherpunkArmory/UserLAnd

/** Handle dedicated volume buttons as virtual keys if applicable. */
private boolean handleVirtualKeys(int keyCode, KeyEvent event, boolean down) {
  InputDevice inputDevice = event.getDevice();
  if (inputDevice != null && inputDevice.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
    // Do not steal dedicated buttons from a full external keyboard.
    return false;
  } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
    mVirtualControlKeyDown = down;
    return true;
  } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
    mVirtualFnKeyDown = down;
    return true;
  }
  return false;
}

代码示例来源:origin: termux/termux-float

/**
   * Handle dedicated volume buttons as virtual keys if applicable.
   */
  private boolean handleVirtualKeys(int keyCode, KeyEvent event, boolean down) {
    InputDevice inputDevice = event.getDevice();
    if (inputDevice != null && inputDevice.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
      // Do not steal dedicated buttons from a full external keyboard.
      return false;
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
      mVirtualControlKeyDown = down;
      return true;
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
      mVirtualFnKeyDown = down;
      return true;
    }
    return false;
  }
}

代码示例来源:origin: SachinVin/citra_android

/**
 * Saves the provided key input setting both to the INI file (so native code can use it) and as
 * an Android preference (so it persists correctly and is human-readable.)
 *
 * @param keyEvent KeyEvent of this key press.
 */
private void saveKeyInput(KeyEvent keyEvent)
{
 InputDevice device = keyEvent.getDevice();
 String bindStr = "Device '" + device.getDescriptor() + "'-Button " + keyEvent.getKeyCode();
 String uiString = device.getName() + ": Button " + keyEvent.getKeyCode();
 saveInput(bindStr, uiString);
}

代码示例来源:origin: SachinVin/citra_android

public boolean onKeyEvent(int keyCode, KeyEvent event)
{
 Log.debug("[MotionAlertDialog] Received key event: " + event.getAction());
 switch (event.getAction())
 {
  case KeyEvent.ACTION_DOWN:
   if (!mControllerMappingHelper.shouldKeyBeIgnored(event.getDevice(), keyCode))
   {
    saveKeyInput(event);
   }
   // Even if we ignore the key, we still consume it. Thus return true regardless.
   return true;
  default:
   return false;
 }
}

代码示例来源:origin: SachinVin/citra_android

@Override
public boolean dispatchKeyEvent(KeyEvent event)
{
 if (mMenuVisible)
 {
  return super.dispatchKeyEvent(event);
 }
 int action;
 switch (event.getAction())
 {
  case KeyEvent.ACTION_DOWN:
   // Handling the case where the back button is pressed.
   if (event.getKeyCode() == KeyEvent.KEYCODE_BACK)
   {
    onBackPressed();
    return true;
   }
   // Normal key events.
   action = NativeLibrary.ButtonState.PRESSED;
   break;
  case KeyEvent.ACTION_UP:
   action = NativeLibrary.ButtonState.RELEASED;
   break;
  default:
   return false;
 }
 InputDevice input = event.getDevice();
 return NativeLibrary.onGamePadEvent(input.getDescriptor(), event.getKeyCode(), action);
}

代码示例来源:origin: ouya/ouya-sdk-examples

InputDevice device = keyEvent.getDevice();
if (null != device) {
  String text = "KeyCode=(" + keyCode + ") "

相关文章