初次是基于像素得,因为手机不同需要修改。
import time
import os
# 获取APP名称
def get_app_name():
app_name = os.popen('adb shell dumpsys window w |findstr \/ |findstr name=')
print(app_name)
# 呼醒屏幕
def wake_up():
# 获取电源状态
power_state = os.popen(
"adb shell dumpsys power | findstr \"Display Power: state=\"").read().strip('\n')
if power_state.split('=')[-1] == 'OFF':
print("唤醒屏幕")
os.system('adb shell input keyevent 26')
else:
print("屏幕已开启不需要唤醒")
# 解锁屏幕
def unlock():
# 获取锁屏状态
key_guard = os.popen(
"adb shell dumpsys window policy| findstr \"mShowingLockscreen\"").read().strip('\n').strip()
if (key_guard.split(' ')[0]).split('=')[-1] == 'true':
time.sleep(1)
print("解锁屏保")
# 左右滑动才好解锁,并且延迟100ms启动
os.system('adb shell input swipe 340 865 370 202')
time.sleep(1)
print("输入密码")
os.system('adb shell input tap 280 889')
os.system('adb shell input tap 280 889')
os.system('adb shell input tap 280 889')
os.system('adb shell input tap 562 1611')
else:
print("屏幕已解锁不需要再次解锁")
# 打开APP
def open_app(app_name, app_activity):
msg = os.popen(
"adb shell ps | findstr " + app_name).read().strip('\n')
if msg:
print("APP已启动")
else:
os.system(
'adb shell am start -n ' + app_name + app_activity)
print("APP启动成功")
# 特定操作
def operating():
os.system('adb shell input tap 294 1312')
time.sleep(1)
os.system('adb shell input tap 980 1829')
time.sleep(2)
os.system('adb shell input tap 374 1559')
time.sleep(2)
os.system('adb shell input tap 439 1417')
flag = 0
while flag < 20:
time.sleep(2)
os.system('adb shell input tap 189 1601')
time.sleep(2)
os.system('adb shell input tap 80 140')
time.sleep(2)
os.system('adb shell input swipe 340 865 370 202')
flag = flag + 1
if __name__ == '__main__':
wake_up()
unlock()
open_app("com.taobao.idlefish", "/com.taobao.fleamarket.home.activity.MainActivity")
time.sleep(5)
operating()
来源:CSDN
作者:我就是郑能量
链接:https://blog.csdn.net/weixin_44186072/article/details/103699354