Android:how to get any KeyPress event with example?

前端 未结 3 407
温柔的废话
温柔的废话 2020-12-13 15:50

i want to get the key value when user pressed any key and also perform action based on the key pressed in android.

e.g. if user pressed \'A\' key then i want to get

3条回答
  •  余生分开走
    2020-12-13 16:16

    Zelimir code works if your ssoo version is up to 2.3 If you have this code running in 2.3 it will not works at all, the way to control the event keys in all ssoo version is with dispatchKeyEvent()

    @Override
        public boolean dispatchKeyEvent(KeyEvent event) {
            Log.d("hello", String.valueOf(event.getKeyCode()));
            return super.dispatchKeyEvent(event);
        }
    

    With this, you can control the key pressed in a webview or wherever you are. The only bug is that you can not control the "action button" ... don't know why.

提交回复
热议问题