Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Android KeyEvent and keycode

What is the difference? public boolean onKeyDown (int keyCode, KeyEvent event) The parameters are keyCode,the button,the user pressed,but what is that KeyEvent?

like image 465
user3642735 Avatar asked Dec 11 '22 04:12

user3642735


1 Answers

KeyEvent: Each key press is described by a sequence of key events, Key events are generally accompanied by a key code.

KeyCode: is a constant that define the event, and is defined inside KeyEvent Class.

For example if you want to detect the KeyEvent "ENTER" :

 @Override
  public boolean onKeyDown( int keyCode, KeyEvent event ) {
    if( keyCode == KeyEvent.KEYCODE_ENTER) {
      //Do something...
      return true; 
    }
    return super.onKeyDown( keyCode, event );
  }
like image 178
Jorgesys Avatar answered Dec 31 '22 13:12

Jorgesys