-
Notifications
You must be signed in to change notification settings - Fork 2
/
replace_enter.py
106 lines (98 loc) · 2.47 KB
/
replace_enter.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import pyperclip
import sys,os
import json
import re
import PyHook3
import pythoncom
import win32api,win32gui
from time import time
last = None
if len(sys.argv)==1:
ct = win32api.GetConsoleTitle()
hd = win32gui.FindWindow(0, ct)
win32gui.ShowWindow(hd, 0)
with open('stop_replace.bat','w') as f:
f.write('taskkill /pid {} /f\n'.format(os.getpid()))
f.write('del %0')
combineKey={
'shift':0,
'control':0,
'menu':0,
}
checkList={
',':'Oem_Comma',
'.':'Oem_Period',
';':'Oem_1',
'/':'Oem_2',
'`':'Oem_3',
'[':'Oem_4',
'\\':'Oem_5',
']':'Oem_6',
'\'':'Oem_7',
'-':'Oem_Minus',
'=':'Oem_Plus',
'Enter':'Return',
'Esc':'Escape',
'alt':'menu',
'CapsLock':'Capital',
'PageUp':'Prior',
'PageDown':'Next',
' ':'Space',
'ctrl':'control',
}
def onKeyUp(event):
global combineKey
if event.Key is None: return True
for key in combineKey.keys():
if key in event.Key:
combineKey[key] = 0
return True
return True
def onKeyDown(event):
global combineKey
if event.Key is None: return True
for key in combineKey.keys():
if key in event.Key:
combineKey[key] = time()
return True
for i in range(len(name)):
if keys[i][-1] == event.Key:
for k in keys[i][:-1]:
if (time()-combineKey[k])>3:
break
else:
func[i]()
return True
return True
def rep():
global last
info = pyperclip.paste()
info = info.replace('\n','').replace('\r','')
last = info
pyperclip.copy(info)
def line():
global last
info = pyperclip.paste()
info = info.replace('\n','').replace('\r','')
info = re.sub(r'[\?\!。?!] *',lambda x:x.group()+'\n\n',info)
info = re.sub(' *\. *','.',info)
info = re.sub(r'\.[^0-9,.\[\]][^,.]',lambda x:'.\n\n'+x.group()[-2:],info)
last = info
pyperclip.copy(info)
def app():
global last
info = pyperclip.paste()
last = last+' '+info
pyperclip.copy(last)
if __name__ == '__main__':
base = sys.path[0]
with open(os.path.join(base,'setting.jsonc'),'r') as f:
dic = json.load(f)
name = ['translate','append']
keys = [[checkList[x] if x in checkList else x for x in dic[n]] for n in name]
func = [line,app]
hm = PyHook3.HookManager()
hm.KeyDown = onKeyDown
hm.KeyUp = onKeyUp
hm.HookKeyboard()
pythoncom.PumpMessages()