java keyboard input,Java InputDevice.KEYBOARD_TYPE_ALPHABETIC属性代码示例

@Override

public boolean onKeyDown(int keyCode, KeyEvent event) {

// Pass-through virtual navigation keys

if ((event.getFlags() & KeyEvent.FLAG_VIRTUAL_HARD_KEY) != 0) {

return super.onKeyDown(keyCode, event);

}

boolean handled = false;

boolean detectedGamepad = event.getDevice() != null && ((event.getDevice().getSources() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK ||

(event.getDevice().getSources() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD);

if (detectedGamepad || (event.getDevice() == null ||

event.getDevice().getKeyboardType() != InputDevice.KEYBOARD_TYPE_ALPHABETIC

)) {

// Always try the controller handler first, unless it's an alphanumeric keyboard device.

// Otherwise, controller handler will eat keyboard d-pad events.

handled = controllerHandler.handleButtonDown(event);

}

if (!handled) {

// Try the keyboard handler

short translated = KeyboardTranslator.translate(event.getKeyCode());

if (translated == 0) {

return super.onKeyDown(keyCode, event);

}

// Let this method take duplicate key down events

if (handleSpecialKeys(keyCode, true)) {

return true;

}

// Pass through keyboard input if we're not grabbing

if (!grabbedInput) {

return super.onKeyDown(keyCode, event);

}

conn.sendKeyboardInput(translated, KeyboardPacket.KEY_DOWN, getModifierState(event));

}

return true;

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值