2
2
import numpy
3
3
4
4
def startup ():
5
- global scalar ,scaling_factor ,adb_enable ,adb_path
5
+ global scalar ,scaling_factor ,adb_enable ,adb_path , device
6
6
#检测ADB
7
7
if sys .platform == 'win32' :
8
8
print ('检测模拟器' )
@@ -35,12 +35,31 @@ def startup():
35
35
out = ''
36
36
print (out )
37
37
out = out .splitlines ()
38
- if len (out )> 1 :
39
- out = out [1 ]
40
- if len (out )> 1 :
38
+ if len (out )> 2 :
41
39
print ('监测到ADB设备,默认使用安卓截图' )
42
40
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
44
63
screen = screenshot ([])
45
64
w = screen .shape [0 ]
46
65
h = screen .shape [1 ]
@@ -50,10 +69,10 @@ def startup():
50
69
else :
51
70
print ('修改成桌面版分辨率' )
52
71
if w > h :
53
- comm = [adb_path ,"shell" ,"wm" ,"size" ,"1136x640" ]
72
+ comm = [adb_path ,"-s" , device , " shell" ,"wm" ,"size" ,"1136x640" ]
54
73
subprocess .run (comm ,shell = False )
55
74
elif w <= h :
56
- comm = [adb_path ,"shell" ,"wm" ,"size" ,"640x1136" ]
75
+ comm = [adb_path ,"-s" , device , " shell" ,"wm" ,"size" ,"640x1136" ]
57
76
subprocess .run (comm ,shell = False )
58
77
else :
59
78
print ('未监测到ADB设备,默认使用桌面版' )
@@ -76,13 +95,13 @@ def reset_resolution():
76
95
global adb_enable ,adb_path
77
96
if adb_enable :
78
97
print ('重置安卓分辨率' )
79
- comm = [adb_path ,"shell" ,"wm" ,"size" ,"reset" ]
98
+ comm = [adb_path ,"-s" , device , " shell" ,"wm" ,"size" ,"reset" ]
80
99
subprocess .run (comm ,shell = False )
81
100
82
101
def screenshot (monitor ):
83
102
global adb_enable ,adb_path
84
103
if adb_enable :
85
- comm = [adb_path ,"shell" ,"screencap" ,"-p" ]
104
+ comm = [adb_path ,"-s" , device , " shell" ,"screencap" ,"-p" ]
86
105
#隐藏终端窗口
87
106
if sys .platform == 'win32' :
88
107
startupinfo = subprocess .STARTUPINFO ()
@@ -231,7 +250,7 @@ def touch(pos):
231
250
#print(adb_enable)
232
251
x , y = pos
233
252
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 )]
235
254
#print('Command: ',comm)
236
255
subprocess .run (comm ,shell = False )
237
256
else :
0 commit comments