I want to stop pythoncom working

久未见 提交于 2019-12-10 19:49:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!