Reputation: 443
I have an physical keyboard connected to my android device. I have an application with two buttons and the following two functions handle the KeyEvent:
public boolean onKeyUp(int keyCode, KeyEvent event) {
if(state==State.INI){
char unicodeChar = (char)event.getUnicodeChar();
Log.d("CHAR", "UP: "+Character.toString(unicodeChar)+" - "+Integer.toString(keyCode));
}
return true;
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(state==State.INI){
char unicodeChar = (char)event.getUnicodeChar();
Log.d("CHAR", "DOWN: "+Character.toString(unicodeChar)+" - "+Integer.toString(keyCode));
}
return true;
}
but even it handle the ENTER key doesn't prevent it to be handled by the system :s Per example, i changed the return true to false and i can navigate with the arrow keys between the buttons so with return true it is working for almost every key except ENTER :s
Upvotes: 1
Views: 2732
Reputation: 443
Resolved with:
public boolean dispatchKeyEvent(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
Log.d("CHAR","YOU CLICKED ENTER KEY");
return false;
}
return super.dispatchKeyEvent(e);
};
Upvotes: 2