androidpython-3.xbotsadbandroidviewclient

How to make adb tap fast (ADB+Python)


So I made a bot for a singleplayer android game, using python and adb. The biggest problem is that between each tap there is like a 1 second delay.

I connect to the device like this -

from ppadb.client import Client

def Get_device_adb():
    adb = Client(host="127.0.0.1", port=5037)

    devices = adb.devices()
    if len(devices) == 0:
        print("No device attached")
        quit()

    return devices[0]

device = Get_device_adb()

and use shell input tap to send my taps -

taps = [(225, 750), (350, 800), ...]
for tap in taps:
    device.shell(f"input tap {tap[0]} {tap[1]}")

For the game I need the taps to happen as fast as possible one after another, and currently they have a 1 second delay between them.

By the way, I really want this script to run in python and not in jython

So is there a way to make adb tap faster?


Solution

  • You can try AndroidViewClient/cuelbra using CluebraTester2-public backend and you can get a much higher rate.

    Here is an example script

    #! /usr/bin/env python3
    # -*- coding: utf-8 -*-
    
    import time
    from com.dtmilano.android.viewclient import ViewClient
    
    device, serialno = ViewClient.connectToDeviceOrExit()
    
    kwargs2 = {'useuiautomatorhelper': True}
    vc = ViewClient(device, serialno, **kwargs2)
    
    taps = [(225, 750), (350, 800), (100, 100), (300, 300), (150, 150), (100, 200)]
    for tap in taps:
        print(f'{time.time()}: touching @{tap}')
        vc.touch(tap[0], tap[1])
    

    using an emulator I could obtain

    1635459899.020685: touching @(225, 750)
    1635459899.202344: touching @(350, 800)
    1635459899.522454: touching @(100, 100)
    1635459899.703721: touching @(300, 300)
    1635459899.8933198: touching @(150, 150)
    1635459903.257416: touching @(100, 200)
    

    which gives approx. 1 touch every 200 ms.

    edit

    There's a new answer at https://stackoverflow.com/a/72268342/236465 that reduces the time per click to around 100ms