I tried:
from ppadb.client import Client
adb = Client()
device = adb.devices[0]
device.shell('input tap x y')
but it just takes too long. Is there a faster alternative to it?
I tried:
from ppadb.client import Client
adb = Client()
device = adb.devices[0]
device.shell('input tap x y')
but it just takes too long. Is there a faster alternative to it?
Here's my code to clarify my simple timing test:
import time
from ppadb.client import Client
client = Client()
devices = client.devices()
device = devices[0]
start = time.time()
for _ in range(100):
# device.input_tap(200, 200)
device.shell('input tap 200 200')
print(f"Finished in {time.time() - start:.1f} seconds")
On my system (Win10, Python3.9) this prints values between 6.6 and 7.2 seconds. Using input_tap(x,y)
instead of shell('input tap x y')
doesn't change the timing.
This is an improvement over How to make adb tap fast (ADB+Python) answer.
In that answer, the method suggested achieves a rate of about 200ms per click.
This new solution, using again CulebraTester2-public, but this time using CulebraTester2-client directly instead of through AndroidViewClient (not because I think it may introduce any overhead but just to show another alternative).
#! /usr/bin/env python3
import culebratester_client
import random
import time
N = 100
CONFIGURATION = None
# areas we don't want to click on for the Keep notes app
Y_OFFSET = 200
Y_BOTTOM = 100
def rp(w, h):
x = random.randint(0, w)
y = random.randint(Y_OFFSET, h - Y_BOTTOM)
return culebratester_client.models.point.Point(x, y)
api_instance = culebratester_client.DefaultApi(culebratester_client.ApiClient(CONFIGURATION))
w = api_instance.ui_device_display_width_get().display_width
h = api_instance.ui_device_display_height_get().display_height
points = [rp(w, h) for n in range(N)]
body = culebratester_client.models.click_body.ClickBody(points)
start = time.time()
api_response = api_instance.ui_device_click_post(body=body)
end = time.time()
elapsed = end - start
print(f'{api_response}')
print(f'{N} clicks in {elapsed:.4f} secs ({(elapsed/N)*1000:.2f} ms per click)')
The results are less than half of previous solution:
{'error_message': None, 'status': 'OK', 'status_code': None}
100 clicks in 9.5429 secs (95.43 ms per click)
and if you run it while you have Google Keep open, you can see the clicks