-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhotkeys.py
More file actions
106 lines (89 loc) · 3.07 KB
/
Copy pathhotkeys.py
File metadata and controls
106 lines (89 loc) · 3.07 KB
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
"""
MousePal — Global Hotkeys
"""
import keyboard
class HotkeyManager:
def __init__(self, profile_manager, config, cursor_finder=None, magnifier=None):
self.pm = profile_manager
self.config = config
self.cursor_finder = cursor_finder
self.magnifier = magnifier
self._registered = []
def start(self):
# Profile hotkeys
profiles = self.config.get_all_profiles()
for name, profile in profiles.items():
hotkey = profile.get("hotkey", "")
if hotkey:
try:
cb = self._make_switch_handler(name)
keyboard.add_hotkey(hotkey, cb, suppress=False)
self._registered.append(hotkey)
except Exception:
pass
# Lock toggle
try:
keyboard.add_hotkey("ctrl+alt+l", self._on_lock, suppress=False)
self._registered.append("ctrl+alt+l")
except Exception:
pass
# Panic — reset to Everyday
try:
keyboard.add_hotkey("ctrl+alt+p", self._on_panic, suppress=False)
self._registered.append("ctrl+alt+p")
except Exception:
pass
# Cursor finder
find_hotkey = self.config.get("find_cursor_hotkey", "ctrl+alt+f")
if find_hotkey:
try:
keyboard.add_hotkey(find_hotkey, self._on_find_cursor, suppress=False)
self._registered.append(find_hotkey)
except Exception:
pass
# Magnifier
mag_hotkey = self.config.get("magnifier_hotkey", "ctrl+alt+m")
if mag_hotkey:
try:
keyboard.add_hotkey(mag_hotkey, self._on_magnifier, suppress=False)
self._registered.append(mag_hotkey)
except Exception:
pass
# Speed nudges
nudge_map = [
("ctrl+alt+shift+up", lambda: self._nudge_speed(1)),
("ctrl+alt+shift+down", lambda: self._nudge_speed(-1)),
]
for combo, handler in nudge_map:
try:
keyboard.add_hotkey(combo, handler, suppress=False)
self._registered.append(combo)
except Exception:
pass
def stop(self):
for hotkey in self._registered:
try:
keyboard.remove_hotkey(hotkey)
except Exception:
pass
self._registered.clear()
def reload(self):
self.stop()
self.start()
def _make_switch_handler(self, profile_name):
def handler():
self.pm.switch(profile_name, force=True)
return handler
def _on_lock(self):
self.pm.toggle_lock()
def _on_panic(self):
self.pm.switch("Everyday", force=True)
def _on_find_cursor(self):
if self.cursor_finder:
self.cursor_finder.show()
def _on_magnifier(self):
if self.magnifier:
self.magnifier.toggle()
def _nudge_speed(self, delta):
import mouse
mouse.nudge_mouse_speed(delta)