Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simulating touch using ADB [duplicate]

Tags:

android

adb

touch

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?

like image 932
Uri Goren Avatar asked Dec 27 '11 18:12

Uri Goren


People also ask

How do you simulate a touch event on android?

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.

How do I take a screenshot using ADB?

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.

What are adb shell commands?

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.


2 Answers

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.

like image 172
krz37 Avatar answered Sep 20 '22 21:09

krz37


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

like image 31
taur Avatar answered Sep 18 '22 21:09

taur