KeyCharacterMap in Android?
Can i use InputManagerService for a 开发者_如何学运维Key handling in Android? I need the KEYCODE_DPAD_CENTER event in Android.
Is this possible using code?
Why not to use onKeyDown in Activity:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if((keyCode == KeyEvent.KEYCODE_DPAD_CENTER)) {
Log.d(this.getClass().getName(), "DPAD_CENTER button pressed");
// implement your stuff here
return true;
}
return super.onKeyDown(keyCode, event);
}
EDIT:
To programmatically invoke onKeyDown:
KeyEvent kevent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER);
onKeyDown(KeyEvent.KEYCODE_DPAD_CENTER, kevent);
精彩评论