低级键盘挂钩不在UI线程上 [英] Low level keyboard Hook not at UI thread

查看:80
本文介绍了低级键盘挂钩不在UI线程上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为键盘挂钩创建一个好的库.我使用SetWindowsHookEx方法,并且我注意到,如果我的应用程序的主线程忙,则应该在任何系统KeyDown事件中调用的方法hookProc都不会执行.我认为应该将钩子挂起,以便其他线程负责.那可能吗?我该怎么办?

I want to create a good library for keyboard hook. I use a method SetWindowsHookEx and I have noticed that method hookProc, which should be called at any system KeyDown event, is not executed if the main thread of my app is bussy. I think the hook shold be made so, that the other thread would be responsible for it. Is that possible? How can I do it?

推荐答案

如果挂钩过程超时,系统会将消息传递给 下一个钩子.但是,在Windows 7和更高版本上,该挂钩是无提示的 删除而没有被调用.应用程序无法知道是否已删除该挂钩.

If the hook procedure times out, the system passes the message to the next hook. However, on Windows 7 and later, the hook is silently removed without being called. There is no way for the application to know whether the hook is removed.

我怀疑这就是您正在发生的事情.您的HookProc函数应该非常快:我的所做的只是将键事件推送到std :: vector中.真正的代码在另一个线程中执行.

I suspect this is what’s happening to you. Your HookProc function should be extremely fast: what mine does is just pushing the key event in a std::vector. The real code is executed in another thread.

这篇关于低级键盘挂钩不在UI线程上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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