Search code examples
c#visual-studiodriverinterception

Is there a way to run code before the debugger is paused in Visual Studio 2019/C#?


It's a wierd use case, but here's why:

I'm developing an app that uses a keyboard driver that intercepts the scan codes from attached keyboards. (https://www.oblita.com/interception.html)

The dll is being wrapped in a C# wrapper and used in my project. The problem is, whenever the debugger pauses, the key events cannot be processed (since the program is now stopped). This makes navigating while the debugger is paused very difficult. I was wondering if anyone has a clever way to deal with this. If I had some code I could run before the debugger paused at a breakpoint I could just call input.Unload() and stop the driver from intercepting.

I'm just kind of at a loss, and maybe I simply have to continue using my mouse only while the debugger is paused.


Solution

  • Modify your source code and insert the statement you want executed input.Unload(); on the line immediately above your breakpoint. Then when your breakpoint is hit, the code you want executed will already have been run. After you are done debugging, remove the statement.