How to use ADB to send touch events to device using sendevent command?
Android comes with an input
command-line tool that can simulate miscellaneous input events. To simulate tapping, it's:
input tap x y
You can use the adb shell ( > 2.3.5) to run the command remotely:
adb shell input tap x y
ADB: How to programmatically determine which input device is used for sending touch event with sendevent
Thanks to @AlexP. for the relevant link to the command getevent -pl
. The SO answer he linked did not fully work for me though, so, I had to modify it a bit. This is the one that appears to work for me.
getevent -pl | awk 'BEGIN { RS="add device "; } /^[0-9]/ { print RS $0; }' | grep -B 100 ABS_MT_POSITION_X | awk '/add device/ {print $NF}'
simulating touch using ADB
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 ......
- 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! :)
Source.
can anyone explain this command fully adb shell sendevent [device] [type] [code] [value]?
First you need to find out the name of the touchscreen device on your phone or tablet. You can use this command in adb shell
session:
getevent -pl 2>&1 | sed -n '/^add/{h}/ABS_MT_TOUCH/{x;s/[^/]*//p}'
Let's say the input device name is /dev/input/event0
and you want to emulate a quick tap at coordinates x=300, y=400:
sendevent /dev/input/event0 3 53 300
sendevent /dev/input/event0 3 54 400
sendevent /dev/input/event0 3 48 5
sendevent /dev/input/event0 3 58 50
sendevent /dev/input/event0 0 2 0
sendevent /dev/input/event0 0 0 0
sendevent /dev/input/event0 0 2 0
sendevent /dev/input/event0 0 0 0
The long touch (let's say 1sec long) at the same coordinates would be:
sendevent /dev/input/event0 3 53 300
sendevent /dev/input/event0 3 54 400
sendevent /dev/input/event0 3 48 5
sendevent /dev/input/event0 3 58 50
sendevent /dev/input/event0 0 2 0
sendevent /dev/input/event0 0 0 0
sleep 1
sendevent /dev/input/event0 0 2 0
sendevent /dev/input/event0 0 0 0
For the explanation what those commands mean and do exactly please read Emulating touchscreen interaction with sendevent in Android.
Related Topics
Android Edittext - Finished Typing Event
Android Compass That Can Compensate for Tilt and Pitch
How to Use Setarguments() and Getarguments() Methods in Fragments
Lazy Download Images into Gridview
Error: Could Not Find Com.Google.Gms:Google-Services:4.2.0
Android:Locationmanager VS Google Play Services
Set Dynamic Base Url Using Retrofit 2.0 and Dagger 2
How to Disable Keypad Popup When on Edittext
How to Debug Android Application Line by Line Using Eclipse
Sending a Notification from a Service in Android
How to Change a Tab Background Color When Using Tablayout
How to Open an Android Studio Project in Eclipse
How to Crop an Image in Android
Firebase Overwrites Signin with Google Account
Progressdialog Is Deprecated.What Is the Alternate One to Use