当前位置:网站首页>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()
边栏推荐
- 万物皆可柯里化的 Ramda.js
- 面试攻略系列(二)-- 秒杀系统
- NFS pays special attention to the problem of permissions
- Uni - app - uview Swiper shuffling figure component, click on the links to jump (click to get the item after the row data, remove data operation)
- offset、client、scroll、window.pageYOffset比较
- How to reduce the size of desktop icons after the computer is reinstalled
- ArcEngine(八) 选择要素并高亮显示
- 七夕力扣刷不停,343. 整数拆分(剑指 Offer 14- I. 剪绳子、剑指 Offer 14- II. 剪绳子 II)
- LeetCode 37. Solve Sudoku
- WPF 实现带蒙版的 MessageBox 消息提示框
猜你喜欢

七夕力扣刷不停,343. 整数拆分(剑指 Offer 14- I. 剪绳子、剑指 Offer 14- II. 剪绳子 II)

IDEA Gradle 常遇问题(二)(持续更新)
![行程和用户[阅读理解法]](/img/4b/77bba3c488b5410fdec5c3894c7421.png)
行程和用户[阅读理解法]

客户端连接rtsp的步骤

GIN Bind模式获取参数和表单验证

RobotFramework 之 Setup和Teardown

19、学习MySQL 索引

FFmpeg multimedia file processing (implementation of ffmpeg operation directory and list)

GIN file upload and return

Unity3d_API_Gyroscope 陀螺仪的接口
随机推荐
Record the system calls and C library functions used in this project-2
现在40系显卡都快出来了,为何1060型号的显卡还有这么多人用?
error Trailing spaces not allowed no-trailing-spaces 9:14 error Unexpected trailing comma
[极客大挑战 2019]Upload
剑指 Offer 21. 调整数组顺序使奇数位于偶数前面(循环不变量)
剑指 Offer 43. 1~n 整数中 1 出现的次数(递归、数学)
Sandbox中的进程/线程相关-1
【奖励公示】第23期 2022年7月奖励名单公示:社区明星评选 | 新人奖 | 博客同步 | 推荐奖
Q_06_03 表达式
海康设备获取YV12图像-不用rtsp
FFmpeg相机花屏花图问题解决方法
Unity3d_API_GPS_LocationService
jenkins api create custom pipeline
Unity3d_API_Gyroscope 陀螺仪的接口
pytest 筛选用例
gin的中间件和路由分组
RTSP协议讲解
Professor Chen Qiang's "Machine Learning and R Application" course Chapter 13 Assignment
pytest 之 重运行机制与测试报告
搭建大型分布式服务(四)Docker搭建开发环境安装Mysql