Android keyboard event, android keyboard
I have rewritten the dispatchKeyEvent event in the activity. Will the onKeyDown event not be executed no matter whether the return is TRUE or FALSE?
Some of the information found is not explained as follows:
When the keyboard is pressed
First trigger dispatchKeyEvent
Then, onUserInteraction is triggered.
OnKeyDown again
If you press it and then release it, it is two steps.
Trigger dispatchKeyEvent
Then, onUserInteraction is triggered.
OnKeyUp again
DispatchKeyEvent is used to process and distribute keys. If you want onKeyDown, you can also receive this implementation.
Public boolean dispatchKeyEvent (KeyEvent event ){
Return super. dispatchKeyEvent (event );
}
The Code test is as follows:
In dispatchKeyEvent (KeyEvent event), pressing and lifting are performed. After processing a key operation, whether return true or false, onKeyDown (int keyCode, KeyEvent event) and onKeyUp (int keyCode, KeyEvent event) will not be processed by the key:
1st cases and log information:
public void DEBUG(String str) { Log.d(TAG, str); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub DEBUG(" onKeyDown " + keyCode ); return super.onKeyDown(keyCode, event); } @Override public boolean onKeyLongPress(int keyCode, KeyEvent event) { // TODO Auto-generated method stub DEBUG(" onKeyLongPress " + keyCode ); return super.onKeyLongPress(keyCode, event); } @Override public boolean dispatchKeyEvent(KeyEvent event) { // TODO Auto-generated method stub DEBUG(" dispatchKeyEvent 1 key = " + event.getKeyCode() + " event = " + event.getAction()); if(event.getAction()==KeyEvent.ACTION_DOWN){ DEBUG(" dispatchKeyEvent 2 ACTION_DOWN" + event.getKeyCode() ); return super.dispatchKeyEvent(event); } if(event.getAction()==KeyEvent.ACTION_UP){ DEBUG(" dispatchKeyEvent 3 ACTION_UP" + event.getKeyCode() ); return super.dispatchKeyEvent(event); } return super.dispatchKeyEvent(event); } @Override public boolean onKeyUp(int keyCode, KeyEvent event) { // TODO Auto-generated method stub DEBUG(" onKeyUp " + keyCode); return super.onKeyUp(keyCode, event); }
Log information:
D/testMainActivity (853): dispatchKeyEvent 1 key = 23 event = 0
D/testMainActivity (853): dispatchKeyEvent 2 ACTION_DOWN23
D/testMainActivity (853): onKeyDown 23
D/testMainActivity (853): dispatchKeyEvent 1 key = 23 event = 1
D/testMainActivity (853): dispatchKeyEvent 3 ACTION_UP23
D/testMainActivity (853): onKeyUp 23