9
import winInputHook # NVDA
13
from comtypes import BSTR
16
import nvdajp_dic # Masataka Shinke
18
#import winUser # NVDA
20
import queueHandler # NVDA
21
from logHandler import log # NVDA
29
_nvdajpimeLoader64=None
33
_last_ime_status = 0 ## 2011-02-10 by nishimotz
35
def ime(LastKeyCode,DiffValue,ImeOpenStatus,OldValue,NewValue,TsfMode):
36
global _last_ime_status
37
if config.conf["keyboard"]["speakTypedCharacters"]==False:
39
if (c_wchar_p(DiffValue).value!=""):
40
log.debug( 'LastKeyCode=0x%(f1)02x DiffValue="%(f2)s" ImeOpenStatus=%(f3)d OldValue="%(f4)s" NewValue="%(f5)s" TsfMode=%(f6)d' % \
41
{'f1':LastKeyCode,'f2':DiffValue,'f3':ImeOpenStatus,'f4':OldValue,'f5': NewValue,'f6': TsfMode})
42
if LastKeyCode in (winUser.VK_SPACE,
52
if nvdajp_dic.dic1.has_key(i) & (config.conf["keyboard"]["nvdajp2Key"]==True):
53
if (nvdajp_dic.dic1.get(i)[0]==3) + (config.conf["keyboard"]["nvdajp3Key"]==True):
54
queueHandler.queueFunction(queueHandler.eventQueue,ui.message,nvdajp_dic.dic1.get(i)[2]) # 詳細、フォネティック読み
56
queueHandler.queueFunction(queueHandler.eventQueue,ui.message,i)
57
elif nvdajp_dic.dic1.has_key(i):
58
if (nvdajp_dic.dic1.get(i)[0]!=3) & (config.conf["keyboard"]["nvdajp3Key"]==True):
59
queueHandler.queueFunction(queueHandler.eventQueue,ui.message,nvdajp_dic.dic1.get(i)[2]) # 詳細、フォネティック読み
61
queueHandler.queueFunction(queueHandler.eventQueue,ui.message,i)
63
queueHandler.queueFunction(queueHandler.eventQueue,ui.message,i)
64
elif LastKeyCode in (winUser.VK_BACK,winUser.VK_DELETE):
65
queueHandler.queueFunction(queueHandler.eventQueue,ui.message, c_wchar_p(OldValue[-1]).value)
67
#if DiffValue == u'ー': DiffValue = u'チョーオン'
68
if nvdajp_dic.dic1.has_key(DiffValue): DiffValue = nvdajp_dic.dic1.get(DiffValue)[4]
69
queueHandler.queueFunction(queueHandler.eventQueue,ui.message,c_wchar_p(DiffValue).value)
70
elif (LastKeyCode==winUser.VK_RETURN) & (c_wchar_p(OldValue).value!="") & (config.conf["keyboard"]["nvdajp1Key"]==True):
71
queueHandler.queueFunction(queueHandler.eventQueue,ui.message,c_wchar_p(OldValue).value)
72
## Masataka.Shinke 2011-07-10
73
elif (LastKeyCode in (242,244,25)) & (ImeOpenStatus==1) & (_last_ime_status==0):
74
queueHandler.queueFunction(queueHandler.eventQueue,ui.message,u"にほんごオン")
76
elif (LastKeyCode in (242,243,25)) & (ImeOpenStatus==0) & (_last_ime_status==1):
77
queueHandler.queueFunction(queueHandler.eventQueue,ui.message,u"にほんごオフ")
86
class nvdajpimeLoader64(object):
89
# Create a pipe so we can write to stdin of the loader process.
90
pipeReadOrig, self._pipeWrite = winKernel.CreatePipe(None, 0)
91
# Make the read end of the pipe inheritable.
92
pipeRead = self._duplicateAsInheritable(pipeReadOrig)
93
winKernel.closeHandle(pipeReadOrig)
94
# stdout/stderr of the loader process should go to nul.
95
with file("nul", "w") as nul:
96
nulHandle = self._duplicateAsInheritable(msvcrt.get_osfhandle(nul.fileno()))
97
# Set the process to start with the appropriate std* handles.
98
si = winKernel.STARTUPINFO(dwFlags=winKernel.STARTF_USESTDHANDLES, hSTDInput=pipeRead, hSTDOutput=nulHandle, hSTDError=nulHandle)
99
pi = winKernel.PROCESS_INFORMATION()
100
# Even if we have uiAccess privileges, they will not be inherited by default.
101
# Therefore, explicitly specify our own process token, which causes them to be inherited.
102
token = winKernel.OpenProcessToken(winKernel.GetCurrentProcess(), winKernel.MAXIMUM_ALLOWED)
104
winKernel.CreateProcessAsUser(token, None, u"lib64/nvdajpimeLoader.exe", None, None, True, None, None, None, si, pi)
105
# We don't need the thread handle.
106
winKernel.closeHandle(pi.hThread)
107
self._process = pi.hProcess
109
winKernel.closeHandle(self._pipeWrite)
112
winKernel.closeHandle(pipeRead)
113
winKernel.closeHandle(token)
115
def _duplicateAsInheritable(self, handle):
116
curProc = winKernel.GetCurrentProcess()
117
return winKernel.DuplicateHandle(curProc, handle, curProc, 0, True, winKernel.DUPLICATE_SAME_ACCESS)
120
# Closing the write end of the pipe will cause EOF for the waiting loader process, which will then exit gracefully.
121
winKernel.closeHandle(self._pipeWrite)
122
# Wait until it's dead.
123
winKernel.waitForSingleObject(self._process, winKernel.INFINITE)
124
winKernel.closeHandle(self._process)
128
def internal_keyDownEvent(vkCode,scanCode,extended,injected):
131
if vkCode in [winUser.VK_ESCAPE]:
138
def internal_keyUpEvent(vkCode,scanCode,extended,injected):
146
global _nvdajpimeLoader64
147
if os.environ.get('PROCESSOR_ARCHITEW6432')=='AMD64':
148
_nvdajpimeLoader64=nvdajpimeLoader64()
154
global _nvdajpimeLoader64
155
if _nvdajpimeLoader64:
156
_nvdajpimeLoader64.terminate()
157
_nvdajpimeLoader64=None
161
if __name__ == '__main__':
163
winInputHook.initialize()
164
winInputHook.setCallbacks(keyDown=internal_keyDownEvent,keyUp=internal_keyUpEvent)
166
pythoncom.PumpWaitingMessages()
167
winInputHook.terminate()
b'\\ No newline at end of file'