views:

53

answers:

3

Is there a way to inject keystrokes into the JVM on the Android platform?

I'm looking for something like java.awt.Robot but I don't think that's available on Android

thanks

+3  A: 

It sounds like you need InstrumentationTestCase.sendKeys()

http://developer.android.com/reference/android/test/InstrumentationTestCase.html#sendKeys(java.lang.String)

http://developer.android.com/reference/android/view/KeyEvent.html

Ollie C
This works a treat in test cases when you have properly instantiated `Instrumentation` object but don't try to use this in the normal running of your app, as it doesn't work.
Dave Webb
+2  A: 

You can use:

$ adb -s <serialno> emu event send <event>

where the event description can be something like:

"EV_KEY:KEY_A:1"
dtmilano
A: 

Well I'm actually working on a Synergy port to the android (synergy-foss.org) and I think the best (and only method) for faking out keystrokes on the device itself is to write to /dev/input/uinput. However it seems this is only available with Cyanogen mod

Shaun