-
Notifications
You must be signed in to change notification settings - Fork 3
/
logitech.test.py
106 lines (85 loc) · 2.55 KB
/
logitech.test.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import ctypes
import os
import pynput
import winsound
try:
root = os.path.abspath(os.path.dirname(__file__))+'\logitech.driver.dll'
print(root)
driver = ctypes.CDLL(root)
ok = driver.device_open() == 1 # 该驱动每个进程可打开一个实例
if not ok:
print('Error, GHUB or LGS driver not found')
except FileNotFoundError:
print(f'Error, DLL file not found')
class Logitech:
class mouse:
"""
code: 1:左键, 2:中键, 3:右键
"""
@staticmethod
def press(code):
if not ok:
return
driver.mouse_down(code)
@staticmethod
def release(code):
if not ok:
return
driver.mouse_up(code)
@staticmethod
def click(code):
if not ok:
return
driver.mouse_down(code)
driver.mouse_up(code)
@staticmethod
def scroll(a):
"""
a:没搞明白
"""
if not ok:
return
driver.scroll(a)
@staticmethod
def move(x, y):
"""
相对移动, 绝对移动需配合 pywin32 的 win32gui 中的 GetCursorPos 计算位置
pip install pywin32 -i https://pypi.tuna.tsinghua.edu.cn/simple
x: 水平移动的方向和距离, 正数向右, 负数向左
y: 垂直移动的方向和距离
"""
if not ok:
return
if x == 0 and y == 0:
return
driver.moveR(x, y, True)
class keyboard:
"""
键盘按键函数中,传入的参数采用的是键盘按键对应的键码
code: 'a'-'z':A键-Z键, '0'-'9':0-9, 其他的没猜出来
"""
@staticmethod
def press(code):
if not ok:
return
driver.key_down(code)
@staticmethod
def release(code):
if not ok:
return
driver.key_up(code)
@staticmethod
def click(code):
if not ok:
return
driver.key_down(code)
driver.key_up(code)
if __name__ == '__main__': # 测试
winsound.Beep(800, 200)
def release(key):
if key == pynput.keyboard.Key.end: # 结束程序 End 键
return False
elif key == pynput.keyboard.Key.home: # 移动鼠标 Home 键
Logitech.mouse.move(500,500)
with pynput.keyboard.Listener(on_release=release) as k:
k.join()