Skip to content

Commit adc08dc

Browse files
committed
识别多个安卓并进行选择
1 parent 7bf4323 commit adc08dc

File tree

2 files changed

+44
-21
lines changed

2 files changed

+44
-21
lines changed

action.py

+29-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import numpy
33

44
def startup():
5-
global scalar,scaling_factor,adb_enable,adb_path
5+
global scalar,scaling_factor,adb_enable,adb_path,device
66
#检测ADB
77
if sys.platform=='win32':
88
print('检测模拟器')
@@ -35,12 +35,31 @@ def startup():
3535
out=''
3636
print(out)
3737
out=out.splitlines()
38-
if len(out)>1:
39-
out=out[1]
40-
if len(out)>1:
38+
if len(out)>2:
4139
print('监测到ADB设备,默认使用安卓截图')
4240
adb_enable=True
43-
41+
#check number of devices
42+
devices=[]
43+
for device in out:
44+
device=device.split()
45+
if len(device)==2:
46+
devices.append(device[0])
47+
if len(devices)==1:
48+
device=devices[0]
49+
else:
50+
for idx,device in devices:
51+
print(idx,' ',device)
52+
while True:
53+
try:
54+
idx=int(input('监测到多个安卓设备,请选择想要运行的设备:'))
55+
except ValueError:
56+
print('请输入数字')
57+
continue
58+
else:
59+
break
60+
device=devices[idx]
61+
print('使用设备:',device)
62+
#change resolution
4463
screen=screenshot([])
4564
w=screen.shape[0]
4665
h=screen.shape[1]
@@ -50,10 +69,10 @@ def startup():
5069
else:
5170
print('修改成桌面版分辨率')
5271
if w>h:
53-
comm=[adb_path,"shell","wm","size","1136x640"]
72+
comm=[adb_path,"-s",device,"shell","wm","size","1136x640"]
5473
subprocess.run(comm,shell=False)
5574
elif w<=h:
56-
comm=[adb_path,"shell","wm","size","640x1136"]
75+
comm=[adb_path,"-s",device,"shell","wm","size","640x1136"]
5776
subprocess.run(comm,shell=False)
5877
else:
5978
print('未监测到ADB设备,默认使用桌面版')
@@ -76,13 +95,13 @@ def reset_resolution():
7695
global adb_enable,adb_path
7796
if adb_enable:
7897
print('重置安卓分辨率')
79-
comm=[adb_path,"shell","wm","size","reset"]
98+
comm=[adb_path,"-s",device,"shell","wm","size","reset"]
8099
subprocess.run(comm,shell=False)
81100

82101
def screenshot(monitor):
83102
global adb_enable,adb_path
84103
if adb_enable:
85-
comm=[adb_path,"shell","screencap","-p"]
104+
comm=[adb_path,"-s",device,"shell","screencap","-p"]
86105
#隐藏终端窗口
87106
if sys.platform=='win32':
88107
startupinfo = subprocess.STARTUPINFO()
@@ -231,7 +250,7 @@ def touch(pos):
231250
#print(adb_enable)
232251
x, y = pos
233252
if adb_enable:
234-
comm=[adb_path,"shell","input","tap",str(x),str(y)]
253+
comm=[adb_path,"-s",device,"shell","input","tap",str(x),str(y)]
235254
#print('Command: ',comm)
236255
subprocess.run(comm,shell=False)
237256
else:

yys.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,27 @@ def select_mode():
6363
17 Debug模式
6464
''')
6565
action.alarm(1)
66-
raw = input("选择功能模式:")
67-
try:
68-
index = int(raw)
69-
except:
70-
print('请输入数字')
71-
select_mode()
7266

7367
mode = [0, tupo, yuhun, yuhun2, yuhundanren,\
7468
gouliang, gouliang2, gouliang3,\
7569
baigui, douji, huodong,\
7670
card, chouka, shengxing, mijing, yaoqi,\
7771
qilingdanren, debug]
78-
try:
79-
command = mode[index]
80-
except:
81-
print('数字超出范围')
82-
select_mode()
72+
73+
while True:
74+
try:
75+
index=int(input("选择功能模式:"))
76+
if index<0:
77+
raise Exception('数字超出范围')
78+
command = mode[index]
79+
except ValueError:
80+
print('请输入数字')
81+
continue
82+
except:
83+
print('数字超出范围')
84+
continue
85+
else:
86+
break
8387

8488
if index==0:
8589
action.reset_resolution()

0 commit comments

Comments
 (0)