您可以使用monkeyrunner(Android SDK 附带的一个工具)来执行此操作。
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyView
device = MonkeyRunner.waitForConnection(timeout = 60, deviceId = "DEVICE_ID")
# DEVICE_ID is the device's serial number obtained by running adb devices
# to tap 4 times
for i in range(4):
device.touch(x, y,MonkeyDevice.DOWN_AND_UP)
# to pause
MonkeyRunner.sleep(no_of_seconds)
# to long touch
device.touch(x, y,MonkeyDevice.DOWN)
MonkeyRunner.sleep(no_of_seconds)
# to release the hold
device.touch(x, y,MonkeyDevice.UP)
现在,要将所有这些都包含在重复的 cicle 中,您可以使用 python while 或 for 语句。
monkeyrunner
位于Android-sdk/tools/monkeyrunner
接下来运行它./monkeyrunner
你将进入交互式控制台Jython 2.5.3
或者运行保存的脚本monkeyrunner ../Desktop/level.py