I'm trying to find a workaround for an issue I'm having when debugging C# in Visual Studio 2015. When the application is debugging it will cause the mouse cursor to severely lag when a breakpoint is hit. This is because the application registers hooks for the mouse and keyboard. When a breakpoint is hit the hooks are waiting for input but they won't receive any until the timeout is reached (~5 seconds).
Therefore, I found some solutions online, but nothing that would be relatively straightforward to implement without reworking the hooks. I tried adding a registry entry for LowLevelHooksTimeout to see if I could get Windows to more quickly move on to the next hook event when a breakpoint is hit, but it doesn't seem to make a difference.
Alternatively, using raw input might be the only way to go, but will require a bit of work. Has anyone run into this issue and are there solutions readily available by chance.
https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/f6032ca1-31b8-4ad5-be39-f78dd29952da/hooking-problem-in-windows-7?forum=windowscompatibility
https://security.stackexchange.com/questions/78732/unregistering-keyboard-hooks-by-timeout-expiration
I ended going with this open-source code: http://www.codeproject.com/Articles/17123/Using-Raw-Input-from-C-to-handle-multiple-keyboard
It has the Raw Input API implemented in C#. There's a simple WPF app in there as well that gives device info and such when you press keys (that's what is in the screenshots at the given link). I used the underlying code and integrated it into my application. For example:
if (RawInputHandler == null)
{
RawInputHandler = RawInput.Instance;
RawInputHandler.LoggingEvent += RawInputHandler_LoggingEvent;
RawInputHandler.KeyPressed += RawInputHandler_KeyPressed;
RawInputHandler.MousePressed += RawInputHandler_MousePressed;
}
Meanwhile, in the Raw Input side of things, I invoke these events whenever I detect a relevant event come down the pipe. There's a method called ProcessRawInput(Intpr) where I differentiate between mouse, keyboard, etc. This is done via checking the hardware type in the API's buffer header:
if (_rawBuffer.header.dwType == DeviceType.RIM_TYPE_MOUSE)
{
// Do mouse stuff, invoke event
}
It was a pain, but in the end this API solved the debugging horror of using mouse/keyboard hooks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With