forked from taojy123/KeymouseGo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMiniCombo.py
73 lines (50 loc) · 1.36 KB
/
MiniCombo.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
# Python3
import time
import _thread
from pynput import keyboard
from pynput.keyboard import Key, KeyCode
keyboard_ctl = keyboard.Controller()
combo_vk = None
quit = False
def combo_press(vk):
global combo_vk
global quit
combo_vk = vk
# Press `ESC` to quit
if vk == 27:
quit = True
return
print('---- start combo -----', vk)
while vk == combo_vk:
keyboard_ctl.press(KeyCode.from_vk(vk))
time.sleep(0.002)
assert vk == combo_vk
keyboard_ctl.release(KeyCode.from_vk(vk))
time.sleep(0.1)
print('--------------------------')
def on_press(key):
pass
def on_release(key):
global combo_vk
if isinstance(key, Key):
print('Key:', key.name, key.value.vk)
vk = key.value.vk
elif isinstance(key, KeyCode):
print('KeyCode:', key.char, key.vk)
vk = key.vk
else:
assert False
if vk == combo_vk:
return
_thread.start_new_thread(combo_press, (vk, ))
keyboard_listener = keyboard.Listener(
on_press=on_press,
on_release=on_release)
keyboard_listener.start()
print('========== MiniCombo 小连击 ===========')
print('使用时最小化该窗口,点击键盘上任意按键,开始连击')
print('如需停止或退出,请按下 ESC ')
while not quit:
time.sleep(3)
print('bye!')
time.sleep(0.5)