Вопрос

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.

Это было полезно?

Решение

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()
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top