Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Low level keyboard Hook not at UI thread

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?

like image 664
jozefkarton Avatar asked Mar 20 '26 18:03

jozefkarton


1 Answers

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.

like image 171
qdii Avatar answered Mar 23 '26 22:03

qdii



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!