Using the keys events (keyboard)
August 25th, 2009
No comments
(Android phone – how-to/example)
There are two methods you need to override:
onKeyDown – that is called when the key is pressed
onKeyUp – that is called when the key is released
This is how your code will look like:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
switch (keyCode) {
case KeyEvent.KEYCODE_FOCUS: /* .. code for KEYCODE_FOCUS .. */ break;
…
return super.onKeyDown(keyCode, event);
}
Note1: do not forget to call the super.onKeyDown method, if you want to allow the key to be used in the default mode (example: “back-key” or “power-key” in most of the applications keep the default functionality)
Note2: there is a method you may find useful event.getRepeatCount() that <
Your code should look the same for onKeyUp.












