problem with pyHook module

Chris Westbrook westbc at clw19.com
Wed Dec 28 04:58:06 CET 2005


I want to use the pyHook module to capture all keyboard input and write it 
to a file.  I have a script that works fine with the command prompt, but I 
have a few issues I need help with.  First, I want to be able to set up an 
html page that has a link to this script and have it start running and 
collecting output, and then use some keystroke like alt+f4 to terminate the 
application.  It seems when I run this script from internet explorer after 
placing it in cgi-bin, the log file gets created but nothing is written to 
it.  i'm running xampp with python 24 and all the necessary stuff. 
Eventually I'd like to try to get the shift key with a letter to indicate an 
upper cased letter, but first I at least want to get all the keys written to 
a file.  Can anyone help?  The sscript I'm starting with is below.
#!c:\Python24\python.exe
print "Content-type:text/html\n\n";
import pyHook
f = open('file.log','w')
def onKeyboardEvent(event):

 f.write(event.Key)

 return True
hm = pyHook.HookManager()
hm.KeyDown = onKeyboardEvent
hm.HookKeyboard()
if __name__ == '__main__':
  import pythoncom
  pythoncom.PumpMessages() 




More information about the Python-list mailing list