低级键盘钩子,在WIN7以上版本的问题

最近在项目用到低级键盘钩子。发现一个很奇怪的事情,在开发环境和测试环境下都正常运行的键盘钩子,

到了现场环境,总是偶发性出现 键盘钩子不能用了,而且退出时产生1404 错误。

 

后经过阅读MSDN 的Remark

 

An application installs the hook procedure by specifying the WH_KEYBOARD_LL hook type and a pointer to the hook procedure in a call to the SetWindowsHookEx function.

This hook is called in the context of the thread that installed it. The call is made by sending a message to the thread that installed the hook. Therefore, the thread that installed the hook must have a message loop.

The hook procedure should process a message in less time than the data entry specified in the LowLevelHooksTimeout value in the following registry key:

HKEY_CURRENT_USER\Control Panel\Desktop

The value is in milliseconds. If the hook procedure does not return during this interval, the system will pass the message to the next hook.

Note that debug hooks cannot track this type of hook.

 

发现是现场的机器没有 Lowlevelhookstimeout 这个注册表项目,增加,修改值为10000,重启,解决。

 

这个地方的问题说明,钩子的处理一定要快。其次超时的值应该要记得设置。最好是程序中进行设置一下。

 

转载于:https://www.cnblogs.com/songr/p/5131655.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值