-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
31 lines (25 loc) · 717 Bytes
/
main.py
File metadata and controls
31 lines (25 loc) · 717 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
28
29
30
31
from functools import partial
from pynput.keyboard import Key, KeyCode, Listener
from buffer import Buffer
def on_press(key: KeyCode, buffer: Buffer, debug=False):
"""
place to test
"""
if hasattr(key, "char") and key.char and len(key.char) == 1:
buffer.add(key.char)
elif key == Key.space:
buffer.add(" ")
elif key == Key.enter:
buffer.add("\n")
elif key == Key.backspace:
buffer.pop()
else:
if debug:
print(f"!{key}!")
return
buffer.show()
with Listener(on_press=partial(on_press, buffer=Buffer())) as listener: # type: ignore
try:
listener.join()
except KeyboardInterrupt:
print("KIss")