-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
35 lines (24 loc) · 821 Bytes
/
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
from translator import Translator
from pynput.keyboard import Key, KeyCode, Listener
import pyperclip
def changeLayout():
cb = pyperclip.paste()
output = Translator().translate(cb)
pyperclip.copy(output)
def changeCapitalise():
cb = pyperclip.paste()
output = Translator().change_cap(cb)
pyperclip.copy(output)
combination_to_function = {
frozenset([Key.ctrl_l, Key.space]): changeLayout,
frozenset([Key.ctrl_l, Key.alt_l, Key.space]): changeCapitalise,
}
current_keys = set()
def on_press(key):
current_keys.add(key)
if frozenset(current_keys) in combination_to_function:
combination_to_function[frozenset(current_keys)]()
def on_release(key):
current_keys.clear()
with Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()