forked from GrayTempest-400/warthunder-cv2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.measure.palstance.py
81 lines (71 loc) · 2.21 KB
/
test.measure.palstance.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
71
72
73
74
75
76
77
78
79
80
81
import ctypes
import multiprocessing
from multiprocessing import Process
import pynput
from win32api import GetCursorPos
shift = 'shift'
point = 'point'
total = 'total'
vertical = 'vertical'
horizontal = 'horizontal'
def keyboard(data):
try:
driver = ctypes.CDLL(r'mouse.device.lgs.dll')
ok = driver.device_open() == 1
if not ok:
print('初始化失败, 未安装lgs/ghub驱动')
except FileNotFoundError:
print('初始化失败, 缺少文件')
def move(x, y, absolute=False):
if ok:
if (x == 0) & (y == 0):
return
mx, my = x, y
if absolute:
ox, oy = GetCursorPos()
mx = x - ox
my = y - oy
driver.moveR(mx, my, True)
def press(key):
if key == pynput.keyboard.Key.shift:
data[shift] = True
def release(key):
if key == pynput.keyboard.Key.shift:
data[shift] = False
else:
x, y = 0, 0
if key == pynput.keyboard.Key.end:
return False
elif key == pynput.keyboard.Key.up:
y = -100
elif key == pynput.keyboard.Key.down:
y = 100
elif key == pynput.keyboard.Key.left:
x = -100
elif key == pynput.keyboard.Key.right:
x = 100
elif key == pynput.keyboard.Key.enter:
data[vertical] = 0
data[horizontal] = 0
if x != 0:
if data[shift]:
x = x // 10
data[horizontal] += x
if y != 0:
if data[shift]:
y = y // 10
data[vertical] += y
move(x, y)
print(f'水平:{abs(data[horizontal])}, 垂直:{abs(data[vertical])}')
with pynput.keyboard.Listener(on_press=press, on_release=release) as k:
k.join()
if __name__ == '__main__':
multiprocessing.freeze_support()
manager = multiprocessing.Manager()
data = manager.dict()
data[shift] = False
data[horizontal] = 0
data[vertical] = 0
pk = Process(target=keyboard, args=(data,))
pk.start()
pk.join()