Search code examples
c#thread-safetymessagingsendkeys

Why SendKeys.SendWait() crashes my application


In my console application, SendKeys.SendWait("^c") is called to copy some selected text to the clipboard.

It works fine, but if my console application has focus when this is called, then, instead of throwing an exception, it just closes my application. And then after that things start acting up, like my mouse wheel affecting the zoom instead of scrolling up and down.

Why dose this happen.


Solution

  • ctrl+cis the signal for a Console window to close.

    And the reason the mouse wheel is affecting zoom after it closes is because the application never got a chance to release the ctrl key.

    This can be fixed by changing the ConsoleMode or changeing the Console.TreatControlCAsInput Property.

    Thanks for the help