How to send keys Control + A + B? (keep Control modifier "pressed")

stoj picture stoj · Jun 5, 2012 · Viewed 16k times · Source

When I record this sequence it fails. I know I can send Control + A using Keyboard.SendKeys(control, "A",ModifierKeys.Control) but how do I send a sequence that holds control and releases the letter before pressing the next letter.

Note: the sequence I am looking for is similar to the default Visual Studio shortcut for commenting out a line Control + K + C

Is this maybe something that I just need to use the WinApi for?

Answer

TCS picture TCS · Jun 5, 2012

From what I understand from the SendKeys.Send documentation it would be:

SendKeys.Send("^(KC)")

The following can be found in the remarks:

To specify that any combination of SHIFT, CTRL, and ALT should be held down while several other keys are pressed, enclose the code for those keys in parentheses. For example, to specify to hold down SHIFT while E and C are pressed, use "+(EC)". To specify to hold down SHIFT while E is pressed, followed by C without SHIFT, use "+EC".