我想停止pythoncom的工作 [英] I want to stop pythoncom working

查看:203
本文介绍了我想停止pythoncom的工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写有关pyHook进行按键记录的代码.以下代码为示例:

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()

我想稍后再停止pythoncom的PumpMessages方法(例如5秒钟).但是我找不到任何答案.

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.

我使用:Windows 7,Python2.7

I use: Windows 7, Python2.7

感谢您的回答.

推荐答案

您将不得不使用pythoncom.PumpWaitingMessages,这是阻止的.

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()

这篇关于我想停止pythoncom的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆