HW key emulation

Put your problem here if it does not fit any of the other categories.

HW key emulation

Postby mihoelzl » Mon Apr 04, 2011 3:08 pm


I am trying to implement a small soft keyboard which should simulate HW key events. There should be an Up-Key, a Down-Key and an OK and Cancel Button.

I made my own InputMethodService which is defined in the Manifest file:
Code: Select all
<service android:name="MyInputMethod"
                <action android:name="android.view.InputMethod" />
            <meta-data android:name="android.view.im" android:resource="@xml/method" />>

Inside the service I want to send a KeyEvent to the current Activity. Referring to the Developer Guide I can do this with the following Code:
Code: Select all

      InputConnection ic = getCurrentInputConnection();
      long eventTime = SystemClock.uptimeMillis();
      ic.sendKeyEvent(new KeyEvent(eventTime, eventTime,
      KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_UP, 0, 0, 0, 0,

The Problem here: the InputConnection is null. I tried to manually bind the Service to the activity, start the service, add the Service as Inputmethod to an edittext but nothing seems to work. The InputMethodService does not start in the right LifeCycle.

What am I missing? Any help here?

Once Poster
Once Poster
Posts: 1
Joined: Mon Apr 04, 2011 3:04 pm


Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 14 guests