forked from GrayTempest-400/warthunder-cv2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wt_auto_Arcade.py
70 lines (58 loc) · 1.89 KB
/
wt_auto_Arcade.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from detect import *
import time
import cv2
import ctypes
import keyboard
from win32gui import FindWindow, SetWindowPos
from win32con import HWND_TOPMOST, SWP_NOMOVE, SWP_NOSIZE
show = 'show'
size = 'size'
init = {
show: True, # 显示, Down
size: 200, # 截图的尺寸, 屏幕中心截图周围大小
}
c = cx_cy()
text = 'Realtime Screen Capture Detect'
try:
import os
root = os.path.abspath(os.path.dirname(__file__))
driver = ctypes.CDLL(f'{root}/logitech.driver.dll')
ok = driver.device_open() == 1
if not ok:
print('初始化失败, 未安装罗技驱动')
except FileNotFoundError:
print('初始化失败, 缺少文件')
def move(x: int, y: int):
if (x == 0) and (y == 0):
return
# x和y转换为ctypes支持的整数类型
c_int_x = ctypes.c_int(x)
c_int_y = ctypes.c_int(y)
driver.moveR(c_int_x, c_int_y, True)
def loop():
while True:
t1 = time.perf_counter_ns()
img = capture_screen_around_center(init[size]) # 如果句柄截图是黑色, 不能正常使用, 可以使用本行的截图方法
t2 = time.perf_counter_ns()
target , image= find_specific_purple_edges('detect.jpg' ,show = init[show])
x, y = target
t3 = time.perf_counter_ns()
aim = get_coordinate(init[size], x, y) #转换屏幕坐标
print(aim)
if aim:
x = aim[0]
y = aim[1]
move(x,y)
if keyboard.is_pressed('h'):
print("按下了'h'键,退出函数执行")
break
# 瞄点划线
if aim:
cv2.line(image, aim, (c[0], c[1]), (255, 255, 0), 2)
# 展示图片
cv2.namedWindow(text, cv2.WINDOW_AUTOSIZE)
cv2.imshow(text, image)
SetWindowPos(FindWindow(None, text), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE)
cv2.waitKey(1)
if __name__ == "__main__":
loop()