0

I have an input method which simulates key press as such:

ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, event));
ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, event));

With this method I can open the menu on the device using KeyEvent.KEYCODE_MENU. After i've done this I try to send KeyEvent.KEYCODE_DPAD_UP AND KeyEvent.KEYCODE_DPAD_DOWN to browse the menu, but the focus is still on the activity in the background.

So, for example, when I'm at the launcher, I open the menu, but when I press up or down, the device is browsing the apps on my home screen instead of the options in the menu.

I repeated the same steps with a hardware keyboard, and then the focus jumps to the menu as expected, so I feel this should be able to simulate as well.

Oskar Pålsson
  • 119
  • 1
  • 4
  • 14

1 Answers1

0

Your keyevent is attached to the main activity of your app. One way that I can think of is to register a callback to the activity whenever the user has input on the key pad. The activity will check if menu is brought up(this can be done with a flag). If it is it will update the position of the selection in the menu.

user3806339
  • 144
  • 1
  • 2
  • I don't think the key event is attached to my main activity. My main activity isn't even started. The key event is sent from a service that extends InputMethodService. I want to be able to browse menus and dialogs throughout the system, not just in my activities. – Oskar Pålsson Sep 26 '14 at 07:22