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?
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.