-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
27 lines (17 loc) · 675 Bytes
/
test.py
File metadata and controls
27 lines (17 loc) · 675 Bytes
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
from keyboard.listener import KeyboardListener
def on_key_press(key_info):
print(
f"Key pressed: {key_info['name']} (code: {key_info['keycode']})\n"
)
key_name = key_info['name']
# Example: Block the 'a' key
if key_name == 'a':
print("Blocking 'a' key!")
return False
def on_key_release(key_info):
print(f"Key released: {key_info['name']} (code: {key_info['keycode']})\n")
def on_flags_changed(flags):
print(f"Modifier flags changed: {flags}\n")
# Using as context manager
with KeyboardListener(on_press=on_key_press, on_release=on_key_release, on_flags_changed=on_flags_changed) as listener:
listener.join()