In my application, when the user presses DPAD_LEFT, I want to generate two hits of DPAD_UP. I know that this can be done using the following method:
@Override private boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
keyDownUp(KeyEvent.KEYCODE_DPAD_UP);
keyDownUp(KeyEvent.KEYCODE_DPAD_UP);
return true;
}
return super.onKeyDown(keyCode,event);
}
private void keyDownUp(int a) {
getCurrentInputConnection().sendKeyEvent(
new KeyEvent(KeyEvent.ACTION_DOWN, a));
getCurrentInputConnection().sendKeyEvent(
new KeyEvent(KeyEvent.ACTION_UP, a));
}
But, being able to use the getCurrentInputConnection () method, I need to extend InputMethodService, and this is not possible because my application is already extending another class. Is there any other way to solve this problem?
source
share