Recognising Escape Key

时间:2018-01-11 08:45:42

标签: java android keyboard android-softkeyboard

I'm currently working on a practice program that works with various keyboard inputs so I can understand how they work in Android apps with Java. But I am struggling to get the ESC key to be recognised. The code below doesn't work. Has anyone ever managed to get the ESC key to work in an app? Is it actually possible?

editText.setOnEditorActionListener(new OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
        boolean handled = false;
        if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ESCAPE) {
                textView.setText("Escapekey pressed");
            handled = true;
        } 
        return handled;
    }
});

To summarize, I want the program to recognise the ESC key.

1 个答案:

答案 0 :(得分:0)

Android Emulator 似乎不会将此密钥转发给应用程序,就像例如功能键。在真实设备上通过真实键盘接收这些按键事件对我来说效果很好。

相关问题