How to send KeyEvents through an input method service to a Dialog, or a Spinner menu?
        Posted  
        
            by shutdown11
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by shutdown11
        
        
        
        Published on 2010-04-11T11:29:47Z
        Indexed on 
            2010/04/11
            15:13 UTC
        
        
        Read the original article
        Hit count: 265
        
android
I'm trying to implement an input method service that receives intents sent by a remote client, and in response to those sends an appropriate KeyEvent.
I'm using in the input method service this method
private void keyDownUp(int keyEventCode) {
        getCurrentInputConnection().sendKeyEvent(
                new KeyEvent(KeyEvent.ACTION_DOWN, keyEventCode));
        getCurrentInputConnection().sendKeyEvent(
                new KeyEvent(KeyEvent.ACTION_UP, keyEventCode));
    }to send KeyEvents as in the Simple Sofykeyboard Sample, and it works in the home, in Activities... but it doesn't works when a Dialog or the menu of a Spinner is in foreground.
The events is sent to the parent activity behind the Dialog.
Is there any way to send keys and control the device like using the hardware keys from an input method?
Better explanation on what I'm trying to do:
I am kind of writng an Input Method that allows to control the device from remote. I write in a client (a java application on my desktop pc) a command (for example "UP"), a server on the device with sendBroadcast() sends the intent with the information, and a receiver in the input method gets it and call keyDownUp with the keycode of the DPAD_UP key. It generally works, but when I go to an app that shows a dialog, the keyDownUp method don't sends the key event to the dialog, for example for select the yes or not buttons, but it keeps to control the activty behind the Dialog.
© Stack Overflow or respective owner