I'm writing a unit test and a certain function will be called deep down in the stack if (Control.ModifierKeys == Keys.Control).. I can add a flag or something for the particular case of running a unit test, but it would be too dirty! How can I set ModifierKeys to Ctrl through code? I'm using C#.Net 4.0.
How to hold the Ctrl key down through code
5.2k views Asked by DeveloperInToronto At
2
You could use P/Invoke to call the
keybd_event
function for synthesizing keystrokes.First declare the following:
Then, in your test, use: