python模拟安卓手机点击,支付宝打年兽,未完待续

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


暂时感觉变量名意义不大,如果是一些行业专有名词感觉还是有用的

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值