1. 原理
使用adb指令模拟操作屏幕
2. 准备
2.1 安装python3环境
- 建议安装到默认路径,否则添加安装路径到环境变量
- ubuntu一键安装:
sudo apt-get install python3
2.2 安装adb环境(windows需要将adb路径添加到环境变量)
- windows:很简单,参考其他博文
- ubuntu一键安装:
sudo apt-get install adb
2.3 手机打开usb调试
- 小米手机需要打开允许usb调试操作屏幕
- 提前得知自己手机屏幕分辨率(如:2340*1080)
3. 修改参数
3.1 分辨率改成自己的
## 屏幕分辨率
base_x = 1080
base_y = 2340
3.2 修改刷金币次数
# 刷金币次数
repeat_times = 60
33 设置改局游戏时长
# 游戏时长
playLen = 110
4.完整代码
# -*- coding: utf-8 -*-
import logging
import os
import time
# 屏幕分辨率
base_x = 1080
base_y = 2340
# 刷金币次数
repeat_times = 60
# 游戏时长
playLen = 110
# 日志输出
logging.basicConfig(format='%(asctime)s %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p',
level=logging.DEBUG)
def tap_screen(tap_x, tap_y, sleepTime):
cmd = 'adb shell input tap {x1} {y1}'.format(
x1=tap_x / 1080 * base_x,
y1=tap_y / 2340 * base_y,
)
os.system(cmd)
if sleepTime > 0:
print('等待' + str(sleepTime) + '秒')
time.sleep(sleepTime)
def do_money_work():
print('#1 下一步')
tap_screen(1725, 895, 2)
print('#2 闯关')
tap_screen(1676, 863, 8)
# print('#3 确定')
# tap_screen(2077, 1004, 8)
# 游戏时间
print("#4 等待110")
for innerTime in range(playLen):
tap_screen(1000, 600, 0)
# print(i)
time.sleep(1)
print('#7 再次挑战')
tap_screen(1970, 984, 1)
if __name__ == '__main__':
for i in range(repeat_times):
try:
logging.info('round {}'.format(i + 1))
do_money_work()
except KeyboardInterrupt:
os.system('kill-server')
print('进程停止')
exit(0)