我想阻止pythoncom工作
作者:互联网
我正在编写一个关于pyHook的键盘记录代码.以下代码是示例:
import pythoncom as pc, pyHook as ph
def KeyboardHook(event):
print chr(event.Ascii)
return True
hm = ph.HookManager()
hm.KeyDown = KeyboardHook
hm.HookKeyboard()
pc.PumpMessages()
我想稍后停止pythoncom的PumpMessages方法(例如5秒).但我找不到任何答案.
我用的是:Windows 7,Python2.7
谢谢你的回答.
解决方法:
您将不得不使用未阻止的pythoncom.PumpWaitingMessages.
import pythoncom as pc, pyHook as ph
import time
def KeyboardHook(event):
print chr(event.Ascii)
return True
hm = ph.HookManager()
hm.KeyDown = KeyboardHook
hm.HookKeyboard()
while time.clock() < 5:
pc.PumpWaitingMessages()
标签:python,python-2-7,pyhook,pythoncom 来源: https://codeday.me/bug/20190825/1718758.html