Referencing this thread: http://groups.google.com/group/android-beginners/browse_thread/thread/8a5d8fa9229114d2/ce6e604f52b5318f?pli=1
I know following will send a touch event (5,29) on the device.
adb shell sendevent /dev/input/event0 3 0 5
adb shell sendevent /dev/input/event0 3 1 29
adb shell sendevent /dev/input/event0 1 330 1
adb shell sendevent /dev/input/event0 0 0 0
adb shell sendevent /dev/input/event0 1 330 0
adb shell sendevent /dev/input/event0 0 0 0
However, trying on the real device, it doesn't work. (Tried Nexus S, HTC G2 rooted)
I used
cat /proc/bus/input/devices
or
getevent
to find out which event# is the touch events and send the above code, but no luck. (Actually I tried all event#s, but none of them work)
How do I send touch events using ADB on real devices?
For key events, I know there's:
input keyevent <event_code>
Is there such one for touch events?
I know I can record/playback touch events. However, I am asking for programmatically sending touch events.
Valentin Rocher's method works if you've extended your view, but if you're using an event listener, use this: view. setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { Toast toast = Toast. makeText( getApplicationContext(), "View touched", Toast.
See the (slightly adapted) answer at https://stackoverflow.com/a/18959385/1587329:
You might want to use monkeyrunner like this:
$ monkeyrunner
>>> from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
>>> device = MonkeyRunner.waitForConnection()
>>> device.touch(5, 29, MonkeyDevice.DOWN_AND_UP)
You can also do a drag, start activies etc. Have a look at the api for MonkeyDevice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With