-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevice.py
45 lines (37 loc) · 1.16 KB
/
device.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os.path
import uiautomator2 as u2
import utils
import settings
#全局变量d
d = None
def init_device():
global d
device = u2.connect()
d = device
# 确保目录存在
if not os.path.exists(settings.screenshot_dir):
os.makedirs(settings.screenshot_dir)
return d
def screenshot():
d.screenshot(settings.screenshot_path)
def swipe(scene, direction):
if scene == '副本选择':
start_rx, start_ry = utils.get_random_coordinate_int(374,609)
end_rx, end_ry= utils.get_random_coordinate_int(313,273)
elif scene == '层数选择':
start_rx, start_ry = utils.get_random_coordinate_int(1075,626)
end_rx, end_ry= utils.get_random_coordinate_int(1073,259)
else:
print("swipe: Unkown scene: " + scene)
return
#up向上滚动,down向下滚动
if direction == 'down':
d.swipe(start_rx,start_ry, end_rx,end_ry)
elif direction == 'up':
d.swipe(end_rx,end_ry,start_rx,start_ry)
else:
print("swipe: Unknown direction: " + direction)
return
def click(x, y, bias=None):
rx, ry = utils.get_random_coordinate_int(x, y)
d.click(rx, ry)