关于全局钩子的问题 [英] Question regarding global hooks

查看:140
本文介绍了关于全局钩子的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SetWindowsHookEx函数文档的备注部分找到了这个摘录(https://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85)。 aspx):



要挂钩64位Windows安装的桌面上的所有应用程序,请安装32位全局挂钩和64位全局挂钩,每个来自适当的进程,并确保在挂钩应用程序中保留消息以避免阻止正常运行。如果您已经有一个32位全局挂钩应用程序并且它不需要运行每个应用程序的上下文,您可能不需要创建64位版本。



我无法理解我在Bold中突出显示的部分。我是WinApi的新手,所以我可能缺乏一定程度的理解。知道我们应该输出什么样的消息。



我尝试了什么:



通过抽取消息,它们是指以下循环:

I found this extract in the 'remarks' section of the documentation for SetWindowsHookEx function ("https://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85).aspx"):

"To hook all applications on the desktop of a 64-bit Windows installation, install a 32-bit global hook and a 64-bit global hook, each from appropriate processes, and be sure to keep pumping messages in the hooking application to avoid blocking normal functioning. If you already have a 32-bit global hooking application and it doesn't need to run in each application's context, you may not need to create a 64-bit version. "

I am unable to understand the portion I have highlighted in Bold. I am new to WinApi's and so I may lack some level of understanding. Any idea as to what kind of messages we are supposed to pump.

What I have tried:

By pumping messages, do they mean the following loop:

while (GetMessage(&msg, NULL, 0, 0) > 0) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

推荐答案

所有这意味着你的hookProc代码传递给它的任何消息都应传递给下一个钩子在使用CallNextHookEx的链中。您可以在此处找到一个示例[ ^ ]。



通常,您不会修改传递给hookProc的值,但没有任何内容表明您在传递消息之前无法修改消息,或者根本不通过消息来过滤掉消息。请记住,这意味着您的应用与其他应用甚至系统本身并没有真正好玩。
All it means is that any messages your hookProc code gets passed into it should be passed to the next hook in the chain using CallNextHookEx. You can find an example of that here[^] in globalKeyboardHook.cs.

Usually, you don't modify the values you get passed into your hookProc, but there's nothing that says you can't modify the messages before you pass them or filter some out by not passing them at all. Keep in mind that this would mean your app doesn't really "play nice" with other apps or even the system itself.


这篇关于关于全局钩子的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆