jclova
jclova

Reputation: 5576

Android: Screen touch event through ADB

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.

Upvotes: 7

Views: 29924

Answers (2)

serv-inc
serv-inc

Reputation: 38297

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.

Upvotes: 2

Veeresh
Veeresh

Reputation: 1052

Use dispatchTouchEvent (MotionEvent event) method of View class to send touch (down,move,up) events

Upvotes: 0

Related Questions