python在子线程中使用pyHook监控键盘无效,需要对WMI进行初始化:
#onKeyboardEvent
def onKeyboardEvent(event):
print "Key:", event.Key
if str(event.Key) ==
'Space':
print "Ok"
return
True
def Keyboard_thread_func(lab):
time.sleep(1)
lab.configure(bg =
"green", text = "Keyboard")
pythoncom.CoInitialize()
hm = pyHook.HookManager()
hm.KeyDown = onKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()
pythoncom.CoUninitialize()