环境
windows 10,python3,adb
import subprocess
import time
# 试试中文变量名
# 变量
adb_help = 'adb help'
adb_connect = 'adb connect'
adb_getevent = 'adb shell getevent'
adb_max_x = 'adb shell getevent -p | find "0035"'
adb_max_y = 'adb shell getevent -p | find "0036"'
比例横 = ''
比例纵 = ''
分辨率横 = 1080
分辨率纵 = 2340
x = '0'
y = '0'
exec_flag = True
# 连接手机
subprocess.Popen(adb_connect, shell=True)
# 横纵坐标获取转换比例
def comp_rate(cmd, size):
pi = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
str = pi.stdout.read()
max_index = str.find('max'.encode())
comma_index = str.find(",".encode(), max_index)
max_v = str[max_index + 4:comma_index]
return size / int(max_v)
比例横 = comp_rate(adb_max_x, 分辨率横)
比例纵 = comp_rate(adb_max_y, 分辨率纵)
print(比例横)
print(比例纵)
# 重复上一次单击事件
def re_tap():
global exec_flag,x,y
if exec_flag:
print("辅助点击:【", x, ",", y, "】")
exec_flag = False
subprocess.Popen(['adb', 'shell', 'input', 'tap', x, y], shell=True)
time.sleep(0.1)
exec_flag = True
# 获取手机事件
pi = subprocess.Popen(adb_getevent, shell=True, stdout=subprocess.PIPE)
for line in iter(pi.stdout.readline, b''):
# 横坐标
if line.__contains__("0035".encode()):
x = str(int(line.decode().split(' ')[-1][0:-2], 16)*比例横)
re_tap()
# 纵坐标
elif line.__contains__("0036".encode()):
y = str(int(line.decode().split(' ')[-1][0:-2], 16)*比例纵)
re_tap()
pi.stdout.close()
pi.wait()
暂时感觉变量名意义不大,如果是一些行业专有名词感觉还是有用的