问题
I was writing a code about keylogging by pyHook. The following codes are example:
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()
I want to stop pythoncom's PumpMessages method for a while later (for example five seconds). But I couldn't find any answer to it.
I use: Windows 7, Python2.7
Thanks for answer.
回答1:
You will have to use pythoncom.PumpWaitingMessages
which is not blocking.
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()
来源:https://stackoverflow.com/questions/19629428/i-want-to-stop-pythoncom-working