如何使adb tap快速(adb +Python)



所以我用python和adb制作了一个单人android游戏的bot。最大的问题是每次点击之间有大约1秒的延迟。

我像这样连接到设备-

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()

并使用shell输入tap发送我的tap -

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

对于游戏,我需要一个接一个的点击尽可能快地发生,目前它们之间有1秒的延迟。

顺便说一下,我真的希望这个脚本在python中运行,而不是在jython

那么有没有办法使adb tap更快?

您可以尝试使用CluebraTester2-public后端AndroidViewClient/cuelbra,您可以获得更高的速率

下面是一个示例脚本

#! /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])

使用模拟器我可以得到

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)

给出近似。每200毫秒触摸一次

编辑

在https://stackoverflow.com/a/72268342/236465上有一个新的答案,可以将每次点击的时间减少到100ms左右

最新更新