Passing < or > with modifiers to SendKeys

1.1k Views Asked by At

How to send key events Control+Shift+> or Control+Shift+< in C# using WinForms with SendKeys?

> and < are not listed in the Microsoft keys list.

1

There are 1 best solutions below

7
On

According to the MSDN documentation:

Each key is represented by one or more characters. To specify a single keyboard character, use the character itself. For example, to represent the letter A, pass in the string "A" to the method. To represent more than one character, append each additional character to the one preceding it. To represent the letters A, B, and C, specify the parameter as "ABC".

...

To specify keys combined with any combination of the SHIFT, CTRL, and ALT keys, precede the key code with one or more of the following codes.

Key        Code
SHIFT      +
CTRL       ^
ALT        %

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)".

I've not used SendKeys in a long time, but I seem to remember needing to wrap a second modifier key in parentheses to get it to work:

"^(+>)"

I remember this being somewhat vague in the documentation, and I can't remember the exact circumstances, but if you've already tried the above, then parentheses may help.