Send Touch Events to a Device via Adb

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 :

  1. Start dump motion event you need to reproduce:

    ~$ adb shell getevent | grep event2

    grep is very useful to filter output.

  2. Do motion event you want to reproduce;

  3. Then just convert all values from hex in dump to decimal values! :)


To find what eventX is working for you do following:

  1. Start terminal and type:

    ~$ adb shell getevent

You will see quickly moving traces with for example /dev/input/event4 ......


  1. 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



Leave a reply



Submit