keylogger in Python

simonwittber at gmail.com simonwittber at gmail.com
Sun Jul 31 09:52:57 EDT 2005


Michael Hoffman wrote:
> I think this is going to be much harder than you think, and I imagine
> this will only end in frustration for you. You will not be able to do it
> well with just Python. I would recommend a different fun project.


Actually, it's pretty easy, using the pyHook and Python win32 modules.
I use code like this to detect when the user is away from the keyboard.

import pyHook
import time
import pythoncom

def OnKeyboardEvent(event):
    print event.Ascii

hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()

while True:
    pythoncom.PumpMessages()


Sw.




More information about the Python-list mailing list