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.
How do I simulate a touch-event and release-event on a given (x,y) coordinate using the ADB shell?
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
grepis 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 ……
- Touch screen once
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! 🙂
I managed to emulate the event on sony xperia LT26i
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