-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
57 lines (46 loc) · 1.44 KB
/
main.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
import pynput.keyboard
import keyboard
from symbols import symbols
# 用于暂存输入的转义字符
current_input = ""
def symbol_input(input_char):
if input_char in symbols:
return symbols[input_char]
else:
return input_char
def on_press(key):
global current_input
try:
if key.char == "\\":
if current_input != "\\":
current_input = "\\"
else:
current_input = ""
keyboard.send("backspace")
elif current_input:
if key.char:
current_input += key.char
except AttributeError:
if key == pynput.keyboard.Key.space:
return
elif key == pynput.keyboard.Key.backspace:
current_input = current_input[:-1]
elif key == pynput.keyboard.Key.shift:
return
else:
current_input = ""
def on_release(key):
global current_input
if key == pynput.keyboard.Key.space:
if current_input in symbols:
for i in range(len(current_input) + 1):
keyboard.send("backspace")
keyboard.write(symbols[current_input])
current_input = ""
return True
def main():
print("running ...")
with pynput.keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
if __name__ == "__main__":
main()