send touch events to a device via adb [duplicate]
Android comes with an input
command-line tool that can simulate miscellaneous input events.
To simulate a tap
, use:
input tap x y
Run the input
command remotely using adb shell
:
adb shell input tap x y
Other options are:
shell@m0:/ $ input
input
usage: input ...
input text <string>
input keyevent <key code number or name>
input [touchscreen|touchpad|touchnavigation] tap <x> <y>
input [touchscreen|touchpad|touchnavigation] swipe <x1> <y1> <x2> <y2> [duration(ms)]
input trackball press
input trackball roll <dx> <dy>
To send touch event you need to do:
-
Set coordinates:
adb shell sendevent /dev/input/event2 3 0 x adb shell sendevent /dev/input/event2 3 1 y
-
Send touch event (must have
0 0 0
pair):adb shell sendevent /dev/input/event2 1 330 1 adb shell sendevent /dev/input/event2 0 0 0
-
Send release finger event (must have
0 0 0
pair):adb shell sendevent /dev/input/event2 1 330 0 adb shell sendevent /dev/input/event2 0 0 0
Please note:
-
You can record events:
adb shell getevent
-
If you use
getevent
all event values are in hex.