-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeystroke_logger.py
More file actions
64 lines (46 loc) · 1.7 KB
/
Copy pathkeystroke_logger.py
File metadata and controls
64 lines (46 loc) · 1.7 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import tkinter as tk
from tkinter import messagebox
from datetime import datetime
logging_active = False
log_file = "key_log.txt"
def start_logging():
global logging_active
logging_active = True
status_label.config(text="Status: Logging Started", fg="green")
messagebox.showinfo("Started", "Keystroke logging has started.\nType inside the text box.")
def stop_logging():
global logging_active
logging_active = False
status_label.config(text="Status: Logging Stopped", fg="red")
messagebox.showinfo("Stopped", f"Keystrokes saved to {log_file}")
def log_key(event):
if not logging_active:
return
key = event.keysym
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
with open(log_file, "a") as f:
f.write(f"{timestamp} : {key}\n")
# GUI window
root = tk.Tk()
root.title("Python Keystroke Logger (Demo)")
root.geometry("500x350")
title = tk.Label(root, text="Keystroke Logging Demonstration", font=("Arial", 16, "bold"))
title.pack(pady=10)
info = tk.Label(
root,
text="Click START and type inside the box below.\nKeystrokes will be saved to a text file.",
font=("Arial", 10)
)
info.pack()
text_box = tk.Text(root, height=8, width=50)
text_box.pack(pady=10)
text_box.bind("<Key>", log_key)
start_btn = tk.Button(root, text="Start Logging", bg="green", fg="white",
font=("Arial", 12), command=start_logging)
start_btn.pack(pady=5)
stop_btn = tk.Button(root, text="Stop Logging", bg="red", fg="white",
font=("Arial", 12), command=stop_logging)
stop_btn.pack(pady=5)
status_label = tk.Label(root, text="Status: Not Started", fg="blue", font=("Arial", 10))
status_label.pack(pady=10)
root.mainloop()