Search code examples
androiddebuggingadb

adb sendevent not working


I want to simulate a touch in an android device, the fastest way possible. I think the fastest is low level (sendevents). I tried with "shell input tap" but it is too slow.

To do this I did:

adb shell getevent

and I've copied the output of my touch event:

/dev/input/event1: 0003 0039 00000867
/dev/input/event1: 0003 0035 00000095
/dev/input/event1: 0003 0036 00000233
/dev/input/event1: 0001 014a 00000001
/dev/input/event1: 0000 0000 00000000
/dev/input/event1: 0003 0039 ffffffff
/dev/input/event1: 0001 014a 00000000
/dev/input/event1: 0000 0000 00000000

After that I did a simple python script to run send this sendevents.

def sendevent (device,event):
    command = "adb -s " + device + " shell sendevent /dev/input/event1 " + event
    print (command)
    os.popen(command)


def touch_position():
    sendevent("fbc690357d04","0003 0039 00000867")
    sendevent("fbc690357d04","0003 0035 00000095")
    sendevent("fbc690357d04","0003 0036 00000233")
    sendevent("fbc690357d04","0001 014a 000000010")
    sendevent("fbc690357d04","0000 0000 00000000")
    sendevent("fbc690357d04","0003 0039 ffffffff")
    sendevent("fbc690357d04","0001 014a 00000000")
    sendevent("fbc690357d04","0000 0000 00000000")

It is now working as I cant see any touch! Can you help me?


Solution

  • When you use getevent to record the events, it will give the output in the hexadecimal notation, so you need to convert them to decimal values. In python you can use int('string', 16) to convert a string in hexadecimal to decimal.