Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 441
jclova Avatar asked Mar 18 '11 15:03

jclova


People also ask

How do you simulate a touch event on android?

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.


1 Answers

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.

like image 82
serv-inc Avatar answered Oct 24 '22 08:10

serv-inc