This repository contains a professional, highly interactive, and structurally modular Educational Keystroke Monitor written in Python 3. It was developed as Task 04 of the Prodigy InfoTech Cyber Security Internship.
Keyboard event loggers (keyloggers) are powerful tools used in cybersecurity for diagnostic logging, accessibility testing, and input telemetry. However, because they hook low-level input devices, they are also dual-use and are frequently exploited by unauthorized spyware. This project demonstrates:
- Operating system level keyboard hook registration using Python's
pynputlibrary. - Custom, structured key serialization and formatting (e.g. converting space, enter, and control inputs to descriptive tokens).
- Safe, local file operation routines and directory validation.
- Strict compliance with ethical guidelines (foreground execution, transparent logging console display, and explicit user-driven termination).
- Real-Time Keyboard Hooking: Captures alphabetic, numeric, and symbolic keys instantaneously while the script is running.
-
Separation of Concerns: Built in a clean modular structure, keeping formatting and disk operations (
src/keylogger.py) separate from the CLI loop (main.py). -
Special Key Formatting: Translates standard non-printable keys to readable console tokens:
- Space key
$\rightarrow$ [SPACE] - Enter key
$\rightarrow$ [ENTER]\n(creates readable logs) - Backspace key
$\rightarrow$ [BACKSPACE] - Tab key
$\rightarrow$ [TAB] - Modifiers (Shift, Ctrl, Alt)
$\rightarrow$ [SHIFT],[CTRL], etc.
- Space key
- Console Transparency: Prints every logged key to stdout in real-time, ensuring the user is fully aware of the monitoring activity.
-
Safeguarded Local-Only Logs: Records solely to
logs/keystrokes.txt. There is zero network transmission code, scraping of clipboard, or screen capture functionality. - Colorama-Enhanced Interface: Colored command-line diagnostics (Cyan banners, Green startup, Yellow typing feedback, and Red shutdown messages).
- Fault-Tolerant File Execution: Gracefully handles missing directories, writing permissions, and Ctrl+C interruptions without throwing unhandled tracebacks.
- Python 3.8+: The engine hosting the event listener and formatting modules.
- pynput (v1.7.7): Third-party listener library used to hook OS-level keyboard events.
- colorama (v0.4.6): Terminal colorization library to provide a clean and polished console UI.
PRODIGY_CS_04/
│
├── assets/
├── logs/
│ └── keystrokes.txt
├── screenshots/
│ ├── monitoring_started.png
│ ├── monitoring_stopped.png
│ └── code_screenshot.png
│
├── src/
│ └── keylogger.py
│
├── .gitignore
├── main.py
├── README.md
└── requirements.txt
Make sure Python 3 is installed and mapped to your system's PATH.
Open your terminal and clone the repository:
git clone https://github.com/siddesh3448/PRODIGY_CS_04.git
cd PRODIGY_CS_04This isolates the pynput and colorama dependencies:
# Windows
python -m venv venv
venv\Scripts\activate
# macOS / Linux
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtLaunch the application from the root directory:
python main.py(Use python3 main.py or the Python Windows launcher py main.py if python is not default)
============================================================
PRODIGY INFO TECH - CYBER SECURITY INTERNSHIP
Task PRODIGY_CS_04:
Educational Keystroke Monitor
============================================================
Monitoring Started...
Press ESC to stop monitoring.
Hello[SPACE]World[ENTER]
[TAB][BACKSPACE]
Monitoring stopped.
Logs saved successfully.
Hello[SPACE]World[ENTER]
[TAB][BACKSPACE]
Developing this task provided practical insights into:
- Operating System Hooks: Intercepting hardware device driver interrupts via low-level application programming interfaces (APIs) in python.
- Ethical Security Design: Establishing transparency protocols (e.g. console printbacks) to distinguish defensive monitor utilities from stealthy malware (spyware).
- Buffer & IO Handling: Creating dynamic folder structures and sanitizing hardware keys into clean string models.
- Defensive CLI Programming: Ensuring safe teardown processes and preventing terminal hangs during keyboard hook release.
- Interactive Log Viewer: Build a utility interface that parses the raw log formatting to construct full word structures for easier analysis.
- Custom Target Hooks: Filter key listeners to specific application windows (e.g., logging only inside a specific testing window to prevent system-wide logging).
- Log Rotation & Encryption: Implement rotation cycles (e.g. creating new logs every 10 minutes) and encrypt the local keystroke logs with AES-256 to protect them from third-party disk reads.
- Name: Siddesh Mallinath Mange
- Role: Cyber Security Intern at Prodigy InfoTech
- LinkedIn: https://www.linkedin.com/in/siddesh-mallinath-mange-a44689351/
- GitHub: https://github.com/siddesh3448
This project is licensed under the MIT License. Feel free to copy, modify, and distribute it for educational purposes.
If you are using this code for your Prodigy InfoTech internship submission, make sure to read the explanations inside the source comments to fully understand the logic!


