-
Notifications
You must be signed in to change notification settings - Fork 3
/
typo.py
56 lines (50 loc) · 1.18 KB
/
typo.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
import pyxhook
from autocorrect import spell
import pyautogui
import enchant
import short_gui as short_gui
d = enchant.Dict("en_US")
word = ""
new_hook=pyxhook.HookManager()
#selection = 'suggestion'
selection = 'suggestion'
def change(word):
global selection
selection = word
def printCorrect(word):
word_new = spell(word)
if word_new!=word:
for i in word:
pyautogui.press('backspace')
pyautogui.press('backspace')
pyautogui.typewrite(word_new+" ")
def print_suggested_word(word_new):
global word
for i in word:
pyautogui.press('backspace')
pyautogui.press('backspace')
pyautogui.typewrite(word_new+" ")
def OnKeyPress(event):
global word
global new_hook
if event.Ascii == 96:
new_hook.cancel()
if (event.Ascii >= 65 and event.Ascii <= 90) or (event.Ascii >= 97 and event.Ascii <= 122):
word += event.Key
if event.Ascii == 32:
if selection == "corrector":
printCorrect(word)
else:
short_gui.set_list(suggest_list(word))
word = ""
def suggest_list(word):
global d
return d.suggest(word)
def main():
global new_hook
#listen to all keystrokes
new_hook.KeyDown=OnKeyPress
#hook the keyboard
new_hook.HookKeyboard()
#start the session
new_hook.start()