import os
import time
num = 0
cdx = False
isf = True
ab = ''
while True:
dvs = os.popen("adb devices").readlines()
for ss in dvs:
ss = ss.strip('\n')
if 'List of devices' not in ss and len(ss) > 6 and 'offline' not in ss:
dv = ss.split('\t')[0]
if isf:
if not ab:
ab = input('is send key 26?\n')
if ab:
os.system("adb -s %s shell input keyevent 26" % dv)
time.sleep(1)
print(dv)
os.system("adb -s %s shell input tap 1130 36" % dv)
cdx = True
time.sleep(1)
isf = False
if cdx:
num += 1
sd = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
print('%s —— 次数%d' % (sd, num))
time.sleep(4.6 * 60)
else:
print('没有连接设备')
input()
break
cdx = False
修改版
import os
import time
num = 0
cdx = False
while True:
dvs = os.popen("adb devices").readlines()
for ss in dvs:
ss = ss.strip('\n')
if 'List of devices' not in ss and len(ss) > 6 and 'offline' not in ss:
dv = ss.split('\t')[0]
print(dv)
dsw = os.popen("adb -s %s shell dumpsys window" % dv).read()
if 'mAwake=false' in dsw and 'mScreenOnEarly=false' in dsw and 'mScreenOnFully=false' in dsw:
os.system("adb -s %s shell input keyevent 26" % dv)
time.sleep(1)
else:
os.system("adb -s %s shell input tap 1130 36" % dv)
time.sleep(1)
cdx = True
if cdx:
num += 1
sd = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
print('%s —— 次数%d' % (sd, num))
time.sleep(3.9 * 60)
else:
print('没有连接设备')
input()
break
cdx = False
最终版:
import os
import subprocess
import time
num = 0
cdx = False
def run_silently(cmd: str) -> str:
with os.popen(cmd) as fp:
bf = fp._stream.buffer.read()
try:
return bf.decode().strip()
except UnicodeDecodeError:
return bf.decode('gbk').strip()
while True:
dvs = os.popen("adb devices").readlines()
for ss in dvs:
ss = ss.strip('\n')
if 'List of devices' not in ss and len(ss) > 6 and 'offline' not in ss:
dv = ss.split('\t')[0]
print(dv)
# dsw = run_silently("adb -s %s shell dumpsys window" % dv)
# process = os.popen("adb -s %s shell dumpsys window" % dv)
# dsw = process.read()
# process.close()
p = subprocess.Popen("adb -s %s shell dumpsys window" % dv, stdout=subprocess.PIPE)
result = p.communicate()
dsw = result[0].decode('utf-8')
if 'mAwake=false' in dsw and 'mScreenOnEarly=false' in dsw and 'mScreenOnFully=false' in dsw:
os.system("adb -s %s shell input keyevent 26" % dv)
time.sleep(1)
else:
os.system("adb -s %s shell input tap 1130 36" % dv)
time.sleep(1)
cdx = True
if cdx:
num += 1
sd = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
print('%s —— 次数%d' % (sd, num))
time.sleep(3.9 * 60)
else:
print('没有连接设备')
input()
break
cdx = False
最最终版:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# version v1.1
import os
import subprocess
import time
num = 0
tnum = 0
cdx = False
while True:
dvs = os.popen("adb devices").readlines()
for ss in dvs:
ss = ss.strip('\n')
if 'List of devices' not in ss and len(ss) > 6 and 'offline' not in ss:
dv = ss.split('\t')[0]
print(dv)
p = subprocess.Popen("adb -s %s shell dumpsys window" % dv, stdout=subprocess.PIPE)
result = p.communicate()
dsw = result[0].decode('utf-8')
if 'mAwake=false' in dsw and 'mScreenOnEarly=false' in dsw and 'mScreenOnFully=false' in dsw:
os.system("adb -s %s shell input keyevent 26" % dv)
else:
os.system("adb -s %s shell input tap 1130 36" % dv)
cdx = True
time.sleep(0.36)
if cdx:
num += 1
sd = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
print('%s —— 次数%d' % (sd, num))
time.sleep(3.9 * 60)
else:
tnum += 1
print('没有连接设备')
if tnum == 69:
print('------------------------')
tnum = 0
it = input()
if not it:
break
else:
time.sleep(1 * 60)
cdx = False
最最终版2:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# version v1.1
import os
import subprocess
import time
num = 0
tnum = 0
cdx = False
while True:
dvs = os.popen("adb devices").readlines()
for ss in dvs:
ss = ss.strip('\n')
if 'List of devices' not in ss and len(ss) > 6 and 'offline' not in ss:
dv = ss.split('\t')[0]
print(dv)
p = subprocess.Popen("adb -s %s shell dumpsys window" % dv, stdout=subprocess.PIPE)
result = p.communicate()
dsw = result[0].decode('utf-8')
bb = 'mAwake=false' in dsw and 'mScreenOnEarly=false' in dsw and 'mScreenOnFully=false' in dsw
if bb:
p2 = subprocess.Popen("adb -s %s shell dumpsys deviceidle" % dv, stdout=subprocess.PIPE)
result2 = p2.communicate()
dsw2 = result2[0].decode('utf-8')
bb = 'mScreenOn=false' in dsw2
if bb:
os.system("adb -s %s shell input keyevent 26" % dv)
else:
os.system("adb -s %s shell input tap 1130 36" % dv)
cdx = True
time.sleep(0.36)
if cdx:
num += 1
sd = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
print('%s —— 次数%d' % (sd, num))
time.sleep(3 * 60)
else:
tnum += 1
print('没有连接设备')
if tnum == 69:
print('------------------------')
tnum = 0
it = input()
if not it:
break
else:
time.sleep(1 * 60)
cdx = False