ANDROID. Emulate Hardware Keys with an IME. Doesn't work with Dialog and Spinner
<p>I have understand that the only way to inject KeyEvents in the Android System is to implement an Input Method.</p>

<p>I have created my IME with the purpose to control from remote the device.</p>

<p>I emulate the hardware keys using the method 
<pre><code>private void keyDownUp(int keyEventCode) {
        getCurrentInputConnection().sendKeyEvent(
                new KeyEvent(KeyEvent.ACTION_DOWN, keyEventCode));
        getCurrentInputConnection().sendKeyEvent(
                new KeyEvent(KeyEvent.ACTION_UP, keyEventCode));
    }
</pre></code>
in my class that extends InputMethodService.</p>

<p>It works fine until an AlertDialog, or the menu of a Spinner comes in foreground. Also the windows that appears when the Menu key is problematic.
My IME can't get focus on them, and the keyevents are sent to the activity behind them.</p>

<p>Using hardware keys, the Dialog get the focus and you can select the botton on the Dialog.
How can i emulate that, using the IME(or anything else)?</p>
