Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows keyboard hook hangs debugger

I have a plug-in DLL that is launched from a secondary (not GUI) thread in the main application. The DLL must grab keyboard events from the application's main window. I am using SetWindowsHookEx() and it works great.

However, if I hit a breakpoint in Visual Studio while the hook is active, and then press a key, Visual Studio and my application lock up completely. This is a problem because I usually use the F-keys to step through code. If I use the mouse and step forward from Visual Studio's Debug menu, it works fine. But using F10 et al. is such a habit, I usually forget to use the mouse.

Is there anything I can do to get my keyboard shortcuts back? Or a different method to listen to the keyboard?

like image 999
japreiss Avatar asked Jul 17 '26 20:07

japreiss


1 Answers

That's pretty inevitable, the debugger break stops the hook from handling notifications so the keyboard goes dead. Using the remote debugger on another machine is a good way to debug code like this. You'll also want to increase the hook timeout so Windows doesn't destroy the hook while you are debugging, HKEY_CURRENT_USER\Control Panel\Desktop\LowLevelHooksTimeout setting. Assuming you are using WH_KEYBOARD_LL.

like image 67
Hans Passant Avatar answered Jul 19 '26 15:07

Hans Passant



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!