Enhanced Keyboard Logger
A clean, educational Python keyboard logger with improved formatting and readability.
- Clean Output Format: No clutter from modifier keys (Ctrl, Shift, Alt) or navigation keys
- Smart Auto-Save: Automatically saves typed content after 3 seconds of inactivity
- Readable Logs: Timestamped entries with clear separators
- Session Tracking: Records session start/end times and duration
- Graceful Exit: Press ESC to stop logging safely
pip install keyboard
Note: On Windows, the script may require administrator privileges. On Linux, you may need to run with sudo
.
-
Basic Usage:
python keylogger.py
-
The logger will:
- Create a
keystroke_log.txt
file - Display the log file location
- Start capturing keystrokes
- Auto-save after 3 seconds of typing inactivity
- Create a
-
To stop: Press the ESC key
You can customize the logger settings in the main()
function:
logger = KeyboardLogger(
log_file="my_custom_log.txt", # Custom log file name
buffer_time=5 # Save after 5 seconds of inactivity
)
The output is clean and organized:
KEYSTROKE LOG - CLEAN FORMAT
======================================================================
Session Started: 2025-10-09 08:00:00 AM
======================================================================
[2025-10-09 08:00:15 AM]
This is a sample of typed text that appears cleanly in the log.
----------------------------------------------------------------------
[2025-10-09 08:00:45 AM]
Another batch of text after a pause in typing.
----------------------------------------------------------------------
======================================================================
SESSION SUMMARY
======================================================================
Started: 2025-10-09 08:00:00 AM
Ended: 2025-10-09 08:05:30 AM
Duration: 0:05:30
======================================================================
- ✅ Regular alphanumeric keys
- ✅ Space, Enter, Tab
- ✅ Backspace (removes last character)
- ❌ Modifier keys (Ctrl, Alt, Shift, Win/Cmd)
- ❌ Navigation keys (arrows, Page Up/Down, Home/End)
- ❌ Function keys (F1-F12)
- Educational purposes only: This tool is for learning about keystroke logging
- Personal use only: Only use on your own computer
- Privacy: Never use this to monitor others without explicit consent
- Legal compliance: Unauthorized keystroke logging is illegal in most jurisdictions
- Requires appropriate system permissions
- May be flagged by antivirus software (false positive for legitimate educational tools)
- Should not be used on shared or public computers
This is a basic educational implementation. If you're concerned about keystroke logging on your system:
- Keep your OS and security software updated
- Be cautious about running unknown scripts
- Use reputable security software
- Review running processes regularly
For educational purposes only. Use responsibly and ethically.
This is an educational project. Feel free to learn from the code and adapt it for your own learning purposes.
Disclaimer: The authors are not responsible for misuse of this tool. Always respect privacy laws and ethical guidelines.