本文介绍了的onkeydown不火的时候,pressing左,右,上,下​​在Android的箭头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的onkeydown回调InputMethodService适用于大量的硬件键盘按钮,但它不会与左,右,上,下​​箭头火。我该如何处理呢?

OnKeyDown callback in InputMethodService works for a lot of hardware keyboard buttons but It doesn't fire with Left, Right, Up, Down arrow. How can I handle it?

感谢您的关注!

推荐答案

您是否看了的你可以尝试的onkeydown或的onkeyup只接收一个事件并打印出关键code看到的是越来越收到什么:

Have you looked at the developer documentation on handling key events? You could try onKeyDown or onKeyUp to only receive one event and print out the keyCode to see what is getting received:

@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);
  }
}

借助的如果你还在未检测方向键,那么你可能需要重写你的视图的的onkeydown或方法的onkeyup,this类似的问题可能是有用的。

The KeyEvent Object reference gives more details. If you are still not detecting the arrow keys then you may need to override the onKeyDown or onKeyUp method of your View, this similar question might be useful.

这篇关于的onkeydown不火的时候,pressing左,右,上,下​​在Android的箭头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 19:16