InputMethodService中的OnKeyDown回调适用于许多硬件键盘按钮,但它不会使用向左,向右,向上,向下箭头触发。我怎么处理呢?
感谢您的关注!
答案 0 :(得分:4)
您是否看过developer documentation on handling key events?您可以尝试onKeyDown或onKeyUp只接收一个事件并打印出keyCode以查看收到的内容:
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
Log.i("your tag", "Keycode: " + keyCode);
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
leftKeyClick();
return true;
case KeyEvent.KEYCODE_DPAD_RIGHT:
rightKeyClick();
return true;
case KeyEvent.KEYCODE_DPAD_UP:
upKeyClick();
return true;
case KeyEvent.KEYCODE_DPAD_DOWN:
downKeyClick();
return true;
default:
return super.onKeyUp(keyCode, event);
}
}
KeyEvent Object reference gives more details.如果您仍未检测到箭头键,则可能需要覆盖视图的onKeyDown或onKeyUp方法this similar question might be useful.