I am trying to send touch events using batch files (.bat) and the adb shell.
I tried to re-send events I get from the adb shell getevents, and it doesn't work even though the command passes without errors. Any ideas?
How do I simulate a touch-event and release-event on a given (x,y) coordinate using the ADB shell?
Answer. As suggested, the best way to simulate touch events since Nougat (API 24) is by using an accessibility service and the AccessibilityService#dispatchGesture method.
Use the ADB option exec-out instead of shell in the screencap command. For example, adb exec-out screencap screenshot. png. This command will store the screenshot direct on your PC in the folder where you have started the command.
Android Shell Commands. ADB is Android Debug Bridge which is a command line utility included with Google's Android SDK. It provides a terminal interface to control your Android device connected to a computer using a USB. ADB can be used to run shell commands, transfer files, install/uninstall apps, reboot and more.
Since it seems to change depending on the Android version, I suggest you to follow these instructions :
Start dump motion event you need to reproduce:
~$ adb shell getevent | grep event2
grep
is very useful to filter output.
Do motion event you want to reproduce;
Then just convert all values from hex in dump to decimal values! :)
To find what eventX is working for you do following:
Start terminal and type:
~$ adb shell getevent
You will see quickly moving traces with for example /dev/input/event4 ......
You must see between event4 few eventX and these eventX right in the moment of the touch
will be yours input interface for reproducing motion events! :)
Source.
I managed to emulate the event on sony xperia LT26i by using
adb shell getevent | grep event2
to capture input and then converting all values from hex to decimal, and by putting the generated sequence in a shellscript
adb shell sendevent /dev/input/event2 3 57 23710
adb shell sendevent /dev/input/event2 3 53 329
adb shell sendevent /dev/input/event2 3 54 1183
adb shell sendevent /dev/input/event2 3 52 0
adb shell sendevent /dev/input/event2 0 0 0
adb shell sendevent /dev/input/event2 3 57 4294967295
adb shell sendevent /dev/input/event2 0 0 0
I figured from posts in linked forum that line 2 and 3 are setting X and Y position the next 2 lines are touch press and the bottom 2 lines are touch release, I havent figured out what the first line does yet but it is needed for it to work. I hope this is useful to you
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