Android - Get keyboard key press

后端 未结 4 1777
独厮守ぢ
独厮守ぢ 2020-12-08 05:00

I want to catch the press of any key of the softkeyboard. I don\'t want a EditView or TextView in my Activity, the event must be handled from a extended View inside my Activ

4条回答
  •  离开以前
    2020-12-08 05:21

    For handling hardware keys and Back key you could use dispatchKeyEvent(KeyEvent event) in your Activity

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

    UPD: unfortunately you can't handle soft keyboard events (see Handle single key events), unless you develop your own custom keyboard (follow the link to learn how Creating input method).

提交回复
热议问题