Using ADB to sendevent touches to the phone, but cant release
Although not having your environment, I have looked into the issue. There are various articles to be found, as you did, which always seem to work for some people but not for others. It is my conclusion that there are differences between combinations of phone-hardware/Android-version/SDK-version that make it so that there is no one solution for all setups.
You will have to find out what works for you. keeping in mind that a major update of the software can always send you back to the starting point.
The simplest method I have found is to use the input tap x y
command :
adb shell input tap x y
Not all input
versions have the tap
parameter, but starting it without
arguments will print all available parameters and the syntax:
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>
Another way is to use Getevent to record the events that happen when you touch the screen. As taken from here:
Record a series of events
Set up the pc to record data in a file (
/tmp/android-touch-events.log
)$ adb shell getevent | grep --line-buffered ^/ | tee /tmp/android-touch-events.log
- do some stuff on the phone
- stop the adb command on the pc with
ctrl-c
Replay the recorded events
This command will do the hex conversion in
awk
$ awk '{printf "%s %d %d %d\n", substr($1, 1, length($1) -1), strtonum("0x"$2), strtonum("0x"$3), strtonum("0x"$4)}' /tmp/android-touch-events.log | xargs -l adb shell sendevent
Beware the gotcha that Getevent displays its parameters in hex but only accepts input in decimal, which the above script tries to correct.
monkeyrunner is another tool that you may use, as demonstrated here:
You might want to use monkeyrunner like this:
$ monkeyrunner >>> from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice >>> device = MonkeyRunner.waitForConnection() >>> device.touch(200, 400, MonkeyDevice.DOWN_AND_UP)
You can also do a drag, start activies etc. Have a look at the api for MonkeyDevice.
References:
- Send touch event from ADB to a device
- How to use ADB to send touch events to device using sendevent command?
Related videos on Youtube
Chris D
Updated on September 18, 2022Comments
-
Chris D over 1 year
I have a HTC 10 which is running CM13 I am trying to send touch events to it by means of ADB and Send Event After sending this:
adb shell sendevent /dev/input/event6 3 57 0 sendevent /dev/input/event6 3 53 300 sendevent /dev/input/event6 3 54 400 sendevent /dev/input/event6 3 48 5 sendevent /dev/input/event6 3 58 50 sendevent /dev/input/event6 0 2 0 sendevent /dev/input/event6 0 0 0
I get a click on the phone, with showtouches on, I can see the touch has begun, but that the touch is still active on the phone.
Based on my reading here and here as well as other places, it seems all I should have to do is:
sendevent /dev/input/event6 3 57 -1 sendevent /dev/input/event6 0 2 0 sendevent /dev/input/event6 0 0 0
or maybe even just
sendevent /dev/input/event6 3 57 -1 sendevent /dev/input/event6 0 0 0
however, neither of these commands results in the touch being ended on the phone.
I tried putting all of this on a shell script on the phone itself, and running the script from the adb shell, however that resulted in the same thing. The beginning of the touch, and not the end.