Android keyboard event, android keyboard

Source: Internet
Author: User

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

 

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.