The approach is simple, just we need to put this code, thats all
Java
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
super.onKeyDown(keyCode, event);
switch(keyCode)
{
case KeyEvent.KEYCODE_CAMERA:
Toast.makeText(KeyActions.this, "Pressed Camera Button", Toast.LENGTH_SHORT).show();
return true;
case KeyEvent.KEYCODE_1:
Toast.makeText(KeyActions.this, "Pressed 1", Toast.LENGTH_SHORT).show();
return true;
case KeyEvent.KEYCODE_HOME:
Toast.makeText(KeyActions.this, "Pressed Home Button", Toast.LENGTH_SHORT).show();
return true;
case KeyEvent.KEYCODE_BACK:
Toast.makeText(KeyActions.this, "Pressed Back Button", Toast.LENGTH_SHORT).show();
Intent result = new Intent("Complete");
setResult(Activity.RESULT_OK, result);
finish();
return true;
}
return false;
}
For every key there is the code, after entering the KeyEvent. the eclipse will show the list of codes available.
If you have doubts means
The full source code
Have a good day.
numbers and other keys can be detected, but how would you detect alphabets?
ReplyDeleteSource code downloading link is not working. Anyone can give me the source code of this project?
ReplyDelete