A Python-based keylogger that captures keystrokes and sends them to a specified Telegram chat using a Telegram bot. The keylogger can be controlled remotely via Telegram commands. This version includes improved threading, queue-based buffering, environment variable configuration, and enhanced error handling for robustness.
- Features
- Prerequisites
- Installation
- Configuration
- Usage
- Commands
- How It Works
- Contributing
- License
- Author
- Disclaimer
- Captures keystrokes in real-time using the
pynputlibrary, including special keys. - Sends keystrokes to a specified Telegram chat in batches via a Telegram bot.
- Supports remote control with
/startand/stopcommands to enable or disable keylogging. - Uses thread-safe queue for keystroke buffering and separate threads for listening and sending.
- Configurable via environment variables for security.
- Comprehensive logging and error handling.
- Python 3.7 or higher
- A Telegram account
- A Telegram bot and its token (obtained from BotFather)
- Your Telegram chat ID
- Required Python packages:
pynputpython-telegram-bot
-
Clone the repository (Datrix Labs members only):
git clone https://github.com/datrixlabs/telegram-keylogger.git cd telegram-keylogger -
Set up a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install pynput python-telegram-bot
-
Create a Telegram bot:
- Open Telegram and search for
@BotFather. - Send
/startand then/newbotto create a new bot. - Follow the instructions to get your
BOT_TOKEN.
- Open Telegram and search for
-
Get your Telegram chat ID:
- Send a message to your bot or use a service like
@GetIDsBotto find yourCHAT_ID.
- Send a message to your bot or use a service like
-
Set environment variables:
- Export the following environment variables:
export TELEGRAM_BOT_TOKEN="your_bot_token_here" export TELEGRAM_CHAT_ID="your_chat_id_here"
- On Windows, use
setinstead ofexport.
Note: Do not hardcode sensitive information in the script. The script will exit if these variables are not set.
- Export the following environment variables:
-
Run the keylogger:
python keylogger.py
-
Control the keylogger:
- Send
/startto the bot to begin capturing keystrokes. - Send
/stopto pause keylogging.
- Send
-
Keystrokes will be collected in a queue and sent in batches (up to 10 at a time) to the specified Telegram chat.
/start: Enables the keylogger to start capturing keystrokes./stop: Disables the keylogger, stopping keystroke capture.
- The script uses the
pynputlibrary to listen for keyboard events in a dedicated listener thread. - Keystrokes are added to a thread-safe queue (
Queue) for buffering. - A separate sender thread processes the queue, sending batches of up to 10 keystrokes to the Telegram chat.
- Threading events (
Event) are used to control capture enabling/disabling and shutdown. - The
python-telegram-botlibrary handles Telegram bot interactions, allowing remote control via commands. - Environment variables are used for configuration to enhance security.
- Logging is configured for info-level messages, with error handling to manage failures gracefully.
Contributions are restricted to Datrix Labs members only, as per the DatrixLabs License v1.0. To contribute:
- Ensure you are an approved member of the Datrix Labs GitHub organization.
- Create a new branch (
git checkout -b feature/your-feature). - Make your changes and commit (
git commit -m "Add your feature"). - Push to the branch (
git push origin feature/your-feature). - Open a pull request for review by the organization owner.
All contributions must retain Datrix Labs attribution and comply with the license terms.
This project is licensed under the DatrixLabs License v1.0.
© DatrixLabs 2025. All Rights Reserved.
- Allowed: Use and modification by Datrix Labs members for internal projects, learning, research, or publication under Datrix Labs. Personal non-commercial use by members. Commercial use requires written permission from the organization owner.
- Not Allowed: Use, modification, or forking by non-members, commercial use without approval, rebranding, redistribution, or public release outside Datrix Labs without consent.
- Special Rules: Only Datrix Labs members may modify the code. All code must retain Datrix Labs attribution. Datrix Labs may audit usage at any time. External contributors must be approved and added to the organization.
See the LICENSE file for full details.
This specific implementation was developed by:
Ronit Paikray
This software is intended for educational and research purposes only. Unauthorized use of keyloggers to capture keystrokes without consent is illegal and unethical. Datrix Labs and the author are not responsible for any misuse of this software.