开发者

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); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜