This project is a modern, rewritten version of the example found in Black Hat Python, 2nd Edition.
- Major Updates: Fully compatible with Python 3.14.
- Key Improvements: Migrated from
pyWinhooktopynputfor event handling and implemented Unicode (Wide) Windows API viactypesto support multi-language window titles (e.g., Traditional Chinese).
- Real-time Keylogging: Captures all keystrokes including special keys.
- Window Tracking: Logs the Process ID (PID), executable name, and active window title.
- Clipboard Monitoring: Automatically captures content when
Ctrl+Vis pressed. - Dual Operation Modes: Choose between Local-Only storage or Auto-Email transmission upon startup.
- Background Mode: Supports
.pywexecution for silent operation. - Email Transmission: Automatically exfiltrates
log.txtvia SMTP every 10 minutes. - Fail-Safe Hygiene: The local
log.txtis only reset after a successful email delivery to prevent data loss. - Encrypted Communication: Uses
STARTTLS(Port 587) to ensure credentials and logs are encrypted during transit. - Secure Credentialing: Implements a GUI-based configuration for App Passwords, avoiding hardcoded secrets in the source code.
Ensure you have Python 3.x installed. Run the following commands to set up the dependencies:
Option 1: Automated Setup (Recommended)
Run the included batch script to install all dependencies and configure Windows system files:
double-click install.bat.
Option 2: Manual Installation
If you prefer not to use the batch script, run the following commands in an elevated Command Prompt:
# Recommended installation command
python -m pip install pynput pywin32
python -m pywin32_postinstall -installTo enable the automated report feature, you must use a Google App Password:
- Enable 2-Step Verification on your Google Account.
- Go to Security > App Passwords.
- Generate a new 16-digit code. This is the password you will enter when the program starts.
- Note: Use a dedicated "burner" account for testing to maintain personal account hygiene.
- Save the script as
keylogger.pywfor silent background execution. - Run the script. A configuration dialog will appear.
- Enter your Receiver Email and the 16-digit App Password.
- The program will now run in the background, logging keystrokes and window activity.
- Check your inbox every 10 minutes for the
Keylogger Report. - To Terminate: Since the program runs in background mode, you must close it via Windows Task Manager (Ctrl+Shift+Esc) by ending the
python.exeprocess.
To have keylogger.pyw launch automatically when Windows starts, use one of the following methods:
- Press
Win + Rand enter:shell:startup - Place your
keylogger.pywfile (or a shortcut to it) into this folder. - The script will run automatically on the next login.
✅ Easiest setup — no admin rights required.
⚠️ Only runs after user login; applies to current user only.
Offers the most flexibility — can run at boot, before login, or with a delay.
- Open Task Scheduler (search in Start Menu).
- Click "Create Basic Task" in the right panel.
- Set the trigger to "When the computer starts" or "When I log on".
- Set the action to "Start a program".
- In the Program/script field, enter
pythonw.exe. - In the Add arguments field, enter the full path to your script:
C:\path\to\keylogger.pyw - Complete the wizard and save.
✅ Supports delayed start (useful to wait for network initialization).
✅ Can run without user login by selecting "Run whether user is logged on or not".
- Press
Win + Rand enterregedit. - Navigate to:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run - Right-click → New → String Value.
- Name it anything (e.g.,
KeyloggerService), and set the value to:"C:\Windows\py.exe" "C:\path\to\keylogger.pyw"
✅ Lightweight and persistent.
⚠️ Edit the registry with caution.
| Method | Requires Login | Admin Required | Recommended For |
|---|---|---|---|
| Startup Folder | ✅ Yes | ❌ No | Quick testing |
| Task Scheduler | Optional | ✅ Yes | Production / stable use |
| Registry | ✅ Yes | ❌ No | Lightweight persistent setup |
The log.txt (and the corresponding email body) is structured as follows:
- Header: Contains PID, Process Name, and Window Title (Unicode supported).
- Body: Captured keystrokes, including Numpad digits (0-9) and special keys.
- Clipboard: Records content whenever
Ctrl+Vis detected.
[ PID: 1234 - notepad.exe - 無標題 - 記事本 ]
Hello world! [Enter]
[ PID: 5678 - chrome.exe - Google 搜尋 ]
How to use Python [Enter]
[PASTE] - https://github.com/091cc/keylogger
Last update: April 2026 | Version: KEYLOGGER v3.14