我希望我的应用支持键盘快捷键.许多设备,例如 Asus Transformer
都有带有 Ctrl 键的外部键盘(在 API 级别 11 上可用).我编写了一些代码,以检查 Ctrl 键是否在模拟器中有效:
I want my app to support keyboard shortcuts. Many devices, such as Asus Transformer
have external keyboard which has Ctrl key (available on API Level 11). I've made some code, to check if Ctrl key works in emulator:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if(Build.VERSION.SDK_INT>10 &&
event.getAction()==KeyEvent.ACTION_DOWN &&
event.isCtrlPressed()){
String actionType="NONE";
final int keyCode = event.getKeyCode();
switch(keyCode){
case KeyEvent.KEYCODE_C:
actionType = "COPY";
break;
case KeyEvent.KEYCODE_V:
actionType = "PASTE";
break;
case KeyEvent.KEYCODE_X:
actionType = "CUT";
break;
case KeyEvent.KEYCODE_R:
actionType = "REFRESH";
break;
case KeyEvent.KEYCODE_A:
actionType = "SELECT ALL";
break;
}
Toast.makeText(ctx, actionType, Toast.LENGTH_SHORT).show();
return true;
}
return super.dispatchKeyEvent(event);
}
不幸的是,它在模拟器中不起作用,我无法在真实硬件上检查它.
Unfortunately it doesn't work in emulator and I can't check it on real hardware.
我有两个问题:
1. 它可以在像 Asus Transformer
这样的设备上运行吗?
2.为什么Ctrl键在模拟器中不起作用?
I have two questions:
1. Would it work on device like Asus Transformer
?
2. Why Ctrl key does not work in emulator?
我试图找到问题的答案或解决方案,但 Google 和 SO 都没有帮助.
I tried to find an answer or solution to my problem, but neither Google nor SO helped.
1.它可以在像 Asus Transformer 这样的设备上运行吗?
我用物理键盘(Asus 的标准扩展坞)检查了我的 Asus Transformer TF101,并且您的代码运行良好.我认为您可以毫无问题地使用它.
I've checked on my Asus Transformer TF101 with physical keyboard (standard docking station from Asus) and your code works fine. I think you can use it without problems.
<强>2.为什么 CTRL 键在模拟器中不起作用?
查看可以映射的按钮列表(对于使用 emulator -keyset
的示例)我认为当前版本的模拟器不支持直接 Ctrl
键映射,所以你在这里不走运.
Looking at the list of buttons that can be mapped (for example using emulator -keyset
) I don't think that current version of emulator supports direct Ctrl
key mapping, so you're out of luck here.
这篇关于自定义键盘快捷键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!