当前位置:网站首页>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()
边栏推荐
- 为什么文字不贴合边
- Professor Chen Qiang's "Machine Learning and R Application" course Chapter 14 Assignment
- 正则表达式-re模块
- GIN初探,环境安装
- Final assignment of R language data analysis in a university
- Come and throw eggs.
- NC53 删除链表的倒数第n个节点
- Professor Chen Qiang's "Machine Learning and R Application" course Chapter 15 Homework
- Q_04_06 把它放在一起:传送
- pytest 之 fixture参数化
猜你喜欢

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

The sword refers to the offer, cuts the rope 2

error Trailing spaces not allowed no-trailing-spaces 9:14 error Unexpected trailing comma
![[MRCTF2020]套娃-1](/img/cb/ba780a4929acd9d76f77ab269faff6.png)
[MRCTF2020]套娃-1

技嘉显卡 RGBFusion 不能调光解决方法

Ledong Fire Rescue Brigade was invited to carry out fire safety training for cadres

kustomize entry example and basic syntax instructions

利用信号灯和共享内存实现进程间同步通信

蓝桥历届真题-既约分数

GIN文件上传与返回
随机推荐
Oracle Recovery Tools修复空闲坏块
kustomize entry example and basic syntax instructions
Professor Chen Qiang "application in machine learning and R" course chapter 17
01_iTween_第一天--小球抛物线
Q_06_05 文件结构
关于做2D游戏时,Canvas边界显示在Game窗口的问题
微服务+微信小程序实现社区服务
行程和用户[阅读理解法]
Anta and Huawei Sports Health jointly verify the champion running shoes and lead Chinese sports with innovation
为什么文字不贴合边
蓝桥历届真题-门牌制作
乐东消防救援大队应邀为干部开展消防安全培训
The sword refers to Offer 57 - II. and is a continuous positive sequence of s (sliding window)
pytest 之 重运行机制与测试报告
搭建大型分布式服务(二)搭建会员服务
NC53 删除链表的倒数第n个节点
NC161 二叉树的中序遍历
FFmpeg multimedia file processing (the basic concept of ffmpeg processing stream data)
缓存和数据库一致性问题
Professor Chen Qiang the machine learning and R application course chapter 18 assignments