MS 是否对 Windows Vista 或 7 中的键盘挂钩进行了某些更改?
我使用 SetWindowsHookEx
和 WH_KEYBOARD_LL
在多种语言(AutoIt、C#)中实现了键盘挂钩。我还知道有几个 C++ 程序也有同样的问题。
我没有发布任何代码,因为它们在 Windows XP 中运行得很好。但是,在 Windows 7 下,挂钩有时会“卸载”或停止处理任何其他键。看起来这可能与内存不足有关,但我不太确定。
Microsoft 是否改变了 Vista 或 7 中键盘挂钩的工作方式,添加了一些在某些情况下卸载第三方挂钩的逻辑?
相关问题:
I've implemented keyboard hooks in several languages (AutoIt, C#) using SetWindowsHookEx
and WH_KEYBOARD_LL
. I also know of a couple of C++ programs that have the same issue.
I didn't post any code because they work perfectly in Windows XP. However, under Windows 7, at some point the hooks become "unloaded" or stop processing any further keys. It seems like it may be related to a low memory condition, but I'm not really sure.
Did Microsoft change the way keyboard hooks work in Vista or 7 to add some logic that would unload third-party hooks under certain circumstances?
Related questions:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,当 UAC 在 Vista 中实现时,它已经被修改了很多。然而,这并不是一个常见的抱怨。是的,Windows 很有可能停止回调钩子回调。一项内置功能,可防止操作系统在某个 hooker 未及时处理回调时无响应。它会自动从回调列表中删除,无需任何诊断。
这是基于超时的,当操作系统资源开始不足时,确实可能会出错。就像没有足够的 RAM 并运行大量进程一样,会出现大量分页。对于更高版本的 Windows 来说,这种情况更有可能发生,因为它们需要更多 RAM,并且由于磁盘碎片问题(尤其是分页文件),在升级计算机而不是在安装之前擦除计算机时往往会受到影响。
可以通过添加 HKCU\Control Panel\Desktop\LowLevelHooksTimeout 值(DWORD,例如 10000)来调整超时设置。请访问 superuser.com 询问更多相关问题
Well, it's been tinkered with plenty when UAC was implemented in Vista. Nevertheless, this is not a common complaint. Yes, it is quite possible for Windows to stop calling back the hook callback. A built-in feature to prevent the operating system from getting unresponsive when there is one hooker that doesn't handle the callback in a timely manner. It gets automatically removed from the callback list without any diagnostic.
This is based on a timeout and can indeed trip when the OS is starting to run low on resources. Like not having enough RAM and running lots of processes, getting massive paging. More likely with later versions of Windows since they need more RAM and tend to suffer when the machine was upgraded instead of wiped before the install due to disk fragmentation problems (especially the paging file).
The timeout setting can be tweaked by adding the HKCU\Control Panel\Desktop\LowLevelHooksTimeout value (DWORD, say 10000). Ask more questions about it at superuser.com
前几天我在编写自己的键盘挂钩时遇到了您所描述的相同超时问题。为了解决这个问题,我编写了 hookcallback 过程,以便它异步调用按键事件并立即返回。
这是我的代码的链接,如果您'重新感兴趣。
I ran into the same timeout issue you describe when I was writing my own keyboard hook the other day. To get around the issue, I wrote my hookcallback proc such that it calls a key press event asynchronously and immediately returns.
Here's a link to my code, if you're interested.