0

I use sendevent to simulate complex gestures (clicks, swipes, long clicks with a swipe at the end). the problem is that sendevent is quite slow, 0.1 second per sendevent command in cmd, and click needs 7 sendevent commands. I so understood that sendevent opens the file, writes, closes and so 7 times. how to optimize it?

i know input tap, but input slower than sendevent

my code on python:

import time
from ppadb.client import Client

adb = Client(host='127.0.0.1', port=5037)
devices = adb.devices()
if len(devices) == 0:
    print('Devices not found')
    quit()
device = devices[0]

def sendevent(_type, _code, _value, _deviceName='/dev/input/event4'):
    last_time = time.time()
    device.shell(f"su -c 'sendevent {_deviceName} {_type} {_code} {_value}'")
    print(time.time()-last_time)

def TapScreen(x, y):
    sendevent(EV_ABS, ABS_MT_ID, 0)
    sendevent(EV_ABS, ABS_MT_TRACKING_ID, 0)
    sendevent(1, 330, 1)
    sendevent(1, 325, 1)
    sendevent(EV_ABS, ABS_MT_PRESSURE, 5)
    sendevent(EV_ABS, ABS_MT_POSITION_X, x)
    sendevent(EV_ABS, ABS_MT_POSITION_Y, y)
    sendevent(EV_SYN, SYN_REPORT, 0)
    sendevent(EV_ABS, ABS_MT_TRACKING_ID, -1)
    sendevent(1, 330, 0)
    sendevent(1, 325, 0)
    sendevent(EV_SYN, SYN_REPORT, 0)

EV_ABS             = 3
EV_SYN             = 0
SYN_REPORT         = 0
ABS_MT_ID          = 47
ABS_MT_TOUCH_MAJOR = 48
ABS_MT_POSITION_X  = 53
ABS_MT_POSITION_Y  = 54
ABS_MT_TRACKING_ID = 57
ABS_MT_PRESSURE    = 58

TapScreen(1000, 500)

Is it possible to write all actions into one file and then send them together as one sendevent?

pardon my english, i use google translate :)

NSeed
  • 11
  • 2
  • This could help you: https://stackoverflow.com/questions/69751137/how-to-make-adb-tap-fast-adbpython – Diego Torres Milano Jan 14 '22 at 23:03
  • You could try to bypass sendevent executable and send the necessary data yourself: https://android.googlesource.com/platform/system/core/+/lollipop-release/toolbox/sendevent.c That should allow you to send the commands much faster than every time having to execute su, sendevent and the open the event target and send the codes. – Robert Jan 15 '22 at 12:11

1 Answers1

1

You’re calling adb shell sendevent … for each one of the sendevent commands. If you send all of with just one call to adb shell (Add all send events commands to the same string, separated by ;) then it would run faster (but it is still a bit slow).

E.g.: adb shell “sendevent1 ; sendevent2 ; sendevent3 ; …”

Heitor Paceli
  • 493
  • 6
  • 16
  • this may add many milliseconds, but the sendevent command itself, each time it is called, opens the file, writes it and closes it. and this opening and closing every time takes time. whatever thanks you for the reply :) – NSeed Jan 05 '23 at 07:42