当前位置:网站首页>pyhook3简单应用(1)--实现截图保存功能
pyhook3简单应用(1)--实现截图保存功能
2022-08-09 13:07:00 【论一个测试的养成】
1.安装
【1】首先安装swging :http://www.swig.org/download.html
【2】安装vc++相关:https://blog.csdn.net/qq_38161040/article/details/88203864
【3】pip3 install pyHook3
2.应用
from PIL import ImageGrab
import pythoncom
import PyHook3
import sys
from ctypes import *
QUIT_WORD="EXIT"
QUIT_CONT=QUIT_WORD
N = 0
current_window = None
def OnKeyboardEvent(event):
global current_window, QUIT_WORD, QUIT_CONT, path, N
# 检测目标窗口是否转移(换了其他窗口就监听新的窗口)
if event.Window != current_window:
current_window = event.Window
# 所以调用底层API喊来获取窗口标题
windowTitle = create_string_buffer(512)
windll.user32.GetWindowTextA(event.Window,byref(windowTitle),512)
windowName = windowTitle.value.decode('gbk')
print("窗口名:%s" % windowName)
print("窗口ID:%s" % event.Window)
# 检测击键是否常规按键(非组合键等)
if event.Key == "Escape":
im = ImageGrab.grab()
filename = str(N) + '.png'
im.save(filename)
N += 1
# 判断退出监听指令符
if (event.Key == QUIT_WORD[0]):
QUIT_WORD = QUIT_WORD[1:]
if (len(QUIT_WORD) == 0):
sys.exit()
return False
else:
QUIT_WORD = QUIT_CONT
# 循环监听下一个击键事件
return True
if __name__ == '__main__':
ph = PyHook3.HookManager()
ph.KeyDown = OnKeyboardEvent #绑定键盘事件
# 注册hook并执行
ph.HookKeyboard()
pythoncom.PumpMessages()
边栏推荐
- NC15 求二叉树的层序遍历
- 音视频录入的pts和dts问题
- Professor Chen Qiang's "Machine Learning and R Application" course Chapter 15 Homework
- Jenkins API groovy calling practice: Jenkins Core Api & Job DSL to create a project
- FFmpeg多媒体文件处理(ffmpeg处理流数据的基本概念)
- Q_04_04 Q#类型模型
- pytest 之 allure报告
- 蓝桥杯线上模拟赛——Flex 经典骰子布局
- glibc memory management model freeing C library memory cache
- JS本地存储 sessionStorage和localStorage
猜你喜欢
随机推荐
Realization of RTSP Protocol
客户端连接rtsp的步骤
【奖励公示】第23期 2022年7月奖励名单公示:社区明星评选 | 新人奖 | 博客同步 | 推荐奖
JS轮播图实现
PO、DO、TO、VO、DO、DTO、DAO、POJO都是什么?
pytest 之 fixture参数化
技嘉显卡 RGBFusion 不能调光解决方法
现在40系显卡都快出来了,为何1060型号的显卡还有这么多人用?
FFMPEG multimedia file processing (deletion and renaming of ffmpeg files)
How to solve the 0x80070005 error when the computer is reinstalled and the system is restored
FFmpeg多媒体文件处理(ffmpeg操作目录及list的实现)
FPGA - Summary of bugs in ISE (in update)
Unity3d_API_GPS_LocationService
Q_06_05 文件结构
剑指 Offer 43. 1~n 整数中 1 出现的次数(递归、数学)
Explanation of RTSP protocol
Come and throw eggs.
程序员的七夕怎么过?不会是写代码吧
Professor Chen Qiang the machine learning and R application course chapter 18 assignments
pytest 之 重运行机制与测试报告