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
How to send touch events to an android device as fast as possible using adb shell?
I figured out a way to do it much faster. It doesn't use adb
but it uses monkeyrunner
, another tool that is also included in de Android SDK.
So I run monkeyrunner
and do this:
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
device = MonkeyRunner.waitForConnection()
for i in range(1, 10000):
device.touch(500, 500, 'DOWN_AND_UP')
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.
Sending touch commands to an Android Device
Have you taken a look at monkeyrunner?
Or if you are looking for an automation test framework, you could try robotium.
how to show touches via ADB in android?
I found solution for this by sending event using sendevent command and enabling show touches option in android we can achieve this.
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}'
Related Topics
How to Draw Border on Just One Side of a Linear Layout
How to Center Progress Indicator in Progressdialog Easily (When No Title/Text Passed Along)
Error: File Path Too Long on Windows, Keep Below 240 Characters
How to Get App Install Time from Android
Adding Expandablelistview to Navigationview
How to Control the Scrolling Speed of Recyclerview.Smoothscrolltoposition(Position)
Android - Emulator in Landscape Mode, Screen Does Not Rotate
Android: Last Line of Textview Cut Off
Android: Need to Record Mic Input
How to Create an Avd for Android 4.0
Differencebetween System Apps and Privileged Apps on Android
How to Highlight the Selected Item of Recycler View
Adding Content to a Linear Layout Dynamically
How to Change the Led Intensity of an Android Device
Detect If App Was Downloaded from Android Market