0

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?

dwnppo
  • 1
  • 2
  • How slow is too slow? One hundred clicks takes 6.9 seconds for me. – import random May 16 '22 at 04:40
  • 1
    Not sure if ppadb supports this but you would save a lot of time if you could reuse the shell. Establishing the shell is most likely one of the most time consuming steps. in your code. – Robert May 16 '22 at 07:25
  • @importrandom just one click takes 1-2 seconds. is it because my pc's specs are low, or is just the shell slow? – dwnppo May 16 '22 at 07:35
  • https://stackoverflow.com/questions/69751137/how-to-make-adb-tap-fast-adbpython this solution rate is about 200ms per touch. – Diego Torres Milano May 16 '22 at 23:22

2 Answers2

0

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.

import random
  • 3,054
  • 1
  • 17
  • 22
0

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

keep note

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134