adb按键顺序
1.启动微信
adb shell am start com.tencent.mm/com.tencent.mm.ui.LauncherUI
2. 模拟点击指定位置
adb shell input tap 284 1240
adb shell input tap 424 642
adb shell input tap 399 757
adb shell input tap 245 1254
adb shell input tap 680 702
adb shell input tap 552 689
adb shell input tap 683 621
3. 模拟点击“返回键”
adb shell input keyevent 4
adb shell input keyevent 4
adb shell input keyevent 4
环境搭建
1、 安装python运行环境
2、 安装adb工具,并设置adb环境变量
3、 将手机用数据线连接至电脑(可连接多个)
4、 手机的锁屏设置关掉、微信正常登录、搜狗更新至2019版本
5、双击执行此脚本
步骤
1、python脚本调用adb
2、adb检测当前的手机设备
3、adb模拟按键点击事件
代码
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import os
import subprocess
import time
import random
def getdevs():
out = subprocess.Popen(
'adb devices'.split(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
).communicate()[0]
devs = []
filters = [b'list', b'of', b'device', b'devices', b'attached']
for item in out.split():
if item.lower() not in filters:
devs.append(item)
return devs
class test_phone:
'测试手机'
devnum = ''
linkx = {'a': {1: True},
'c': {1: True},
'h': {1: False},
'j': {1: False},
'm': {1: True, 2: True, 3: True},
#'n': {1: True}
}
def __init__(self, devnum):
self.devnum = devnum
# 唤醒手机
def wake_up_phone(self):
cmd = 'adb -s %s shell input keyevent 26' % self.devnum.decode().strip()
os.system(cmd)
return
# 打开微信
def openwx(self):
cmd = 'adb -s %s shell am start com.tencent.mm/com.tencent.mm.ui.LauncherUI' % self.devnum.decode().strip()
os.system(cmd)
return
# 打开联系人a 1
def open_linkman_x_n(self, x = 'a', n = 1, m = True):
cmd = 'adb -s %s shell input tap 284 1240' % self.devnum.decode().strip()
os.system(cmd)
if (x == 'a'):
cmd = 'adb -s %s shell input tap 710 257' % self.devnum.decode().strip()
elif (x == 'c'):
cmd = 'adb -s %s shell input tap 710 340' % self.devnum.decode().strip()
elif (x == 'h'):
cmd = 'adb -s %s shell input tap 710 487.6' % self.devnum.decode().strip()
elif (x == 'j'):
cmd = 'adb -s %s shell input tap 710 550.5' % self.devnum.decode().strip()
elif (x == 'm'):
cmd = 'adb -s %s shell input tap 710 652.5' % self.devnum.decode().strip()
elif (x == 'n'):
cmd = 'adb -s %s shell input tap 710 695.5' % self.devnum.decode().strip()
os.system(cmd)
if (n == 1):
cmd = 'adb -s %s shell input tap 220 239' % self.devnum.decode().strip()
elif (n == 2):
cmd = 'adb -s %s shell input tap 429 344' % self.devnum.decode().strip()
elif (n == 3):
cmd = 'adb -s %s shell input tap 405 451' % self.devnum.decode().strip()
os.system(cmd)
if (m):
cmd = 'adb -s %s shell input tap 156.8 750' % self.devnum.decode().strip()
else:
cmd = 'adb -s %s shell input tap 156.8 650' % self.devnum.decode().strip()
os.system(cmd)
return
# 发送搜狗信息
def send_sougou_ms(self):
cmd = 'adb -s %s shell input tap 245 1254' % self.devnum.decode().strip()
os.system(cmd)
#time.sleep(5)
cmd = 'adb -s %s shell input tap 680 702' % self.devnum.decode().strip()
os.system(cmd)
#time.sleep(5)
cmd = 'adb -s %s shell input tap 552 689' % self.devnum.decode().strip()
os.system(cmd)
cmd = 'adb -s %s shell input tap 683 621' % self.devnum.decode().strip()
os.system(cmd)
return
# 返回三次
def wx_back(self, n = 3):
cmd = 'adb -s %s shell input keyevent 4' % self.devnum.decode().strip()
while n:
n -= 1
os.system(cmd)
return
devs = getdevs()
while True:
for item in devs:
# 创建手机
phone = test_phone(item)
# 唤醒手机
phone.wake_up_phone()
# 打开微信
phone.openwx()
# 打开微信联系人x n
x = random.sample(phone.linkx.keys(), 1)
n = random.sample(phone.linkx[x[0]].keys(), 1)
phone.open_linkman_x_n(x[0], n[0], phone.linkx[x[0]][n[0]])
# 发送搜狗消息
phone.send_sougou_ms()
# 返回桌面
phone.wx_back()
# 关闭手机
phone.wake_up_phone()
# 随机间隔时间
s = random.randint(100,10000)
while (s):
print('\r等待时长:%d s' % s, end = '')
s -= 1
time.sleep(1)