Low level keyboard Hook not at UI thread

血红的双手。 提交于 2019-12-11 02:21:41

问题


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?


回答1:


Microsoft help page of LowLevelKeyboardProc mentions that

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.

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.



来源:https://stackoverflow.com/questions/10054839/low-level-keyboard-hook-not-at-ui-thread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!