Skip to content

Commit 42e055d

Browse files
committed
FIX: change hotkey window only works once
ADD: wait for all keys to be released
1 parent 30a2c32 commit 42e055d

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

β€Žapp/app.pyβ€Ž

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,24 @@
33

44
from pynput.keyboard import Key, Controller
55

6+
global hotkey
7+
68
# available hotkey keys:
79
# ctrl, alt, shift, windows
810
# Letter keys: a–z
911
# Special keys: enter, esc, space, tab, backspace, up, down, left, right, etc.
1012

13+
def waitUntilRelease(key):
14+
while kb.is_pressed(key):
15+
time.sleep(0.01)
16+
17+
1118
def handle_hotkey(keyboard):
19+
20+
keys = hotkey.split('+')
21+
for key in keys:
22+
waitUntilRelease(key)
23+
1224
# using a different lib to handle shift & home keystrokes
1325
# since keyboard package couldn't do it
1426
keyboard.press(Key.shift)
@@ -22,24 +34,28 @@ def handle_hotkey(keyboard):
2234

2335
# convert the bad text to the correct language and paste it
2436
text = pyperclip.paste()
25-
print(text)
2637
kb.write(string_converter.convert(text))
2738

2839
# change pc language
2940
kb.press_and_release('alt + shift')
3041

3142
def change_hotkey(new_hotkey):
43+
global hotkey
44+
hotkey = new_hotkey
45+
3246
kb.unhook_all()
3347
kb.add_hotkey(new_hotkey, lambda: handle_hotkey(Controller()))
3448

3549
def quit():
36-
# kb.press_and_release('esc')
3750
kb.unhook_all()
3851
os._exit(0)
3952
exit(0)
4053

4154
def main():
42-
kb.add_hotkey('alt + shift + z', lambda: handle_hotkey(Controller()))
55+
global hotkey
56+
hotkey = 'alt+shift+z'
57+
58+
kb.add_hotkey(hotkey, lambda: handle_hotkey(Controller()))
4359
kb.wait()
4460

4561
if __name__ == '__main__':

β€Žapp/sysTray.pyβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def create_text_field():
3434
def on_submit(event=None):
3535
text = entry.get()
3636
if text:
37-
app.change_hotkey(" + ".join(text.lower().replace(' ', '').split(',')))
37+
app.change_hotkey("+".join(text.lower().replace(' ', '').split(',')))
3838
input_dialog.destroy()
39-
root.quit()
39+
root.destroy()
4040

4141
submit_btn = tk.Button(input_dialog, text="Submit", command=on_submit)
4242
submit_btn.pack(pady=10)

β€Žbuild.batβ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
pyinstaller app\sysTray.py ^
22
--onefile ^
33
--icon=translate_icon.ico ^
4-
--add-data "translate_icon.ico;." ^
54
--noconsole ^
5+
--add-data "translate_icon.ico;." ^
66
--name MisType
77

88
rmdir build /S /Q
99
del MisType.spec
1010
move dist\MisType.exe .
1111
rmdir dist
12-
cls
12+
cls
13+

0 commit comments

Comments
Β (0)