Use sendkeys to send the key and key combination to the active application. This class cannot be instantiated. To send a key to a class and continue the program stream immediately, use send. Use sendwait to wait for any process to be started by pressing.
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 the string "a" to the method. To indicate multiple characters, append each additional character to the end of the character before it. To indicate letters A, B, and C, specify the parameter as "ABC ".
Plus sign (+), inserted symbol (^), percent sign (%), wave number (~) And parentheses () have special meanings for sendkeys. To specify a character in these characters, place it in braces. For example, to specify a plus sign, use "{+ }". To specify braces, use "{{}" and "{}}". Brackets ([]) have no special meaning for sendkeys,
But they must be placed in braces. In other applications, brackets have special meanings, which may play an important role in the occurrence of Dynamic Data Exchange (DDE.
System. Windows. Forms. sendkeys
The following are some special key code tables of sendkeys.
Key |
Code |
| Backspace |
{Backspace}, {BS}, or {bksp} |
| Break |
{Break} |
| Caps Lock |
{Capslock} |
| Del or delete |
{Delete} or {del} |
| Down Arrow (down arrow) |
{Down} |
| End |
{End} |
| Enter |
{Enter} Or ~ |
| ESC |
{ESC} |
| Help |
{Help} |
| Home |
{Home} |
| INS or insert |
{Insert} or {ins} |
| Left arrow (left arrow) |
{Left} |
| Num Lock |
{Numlock} |
| Page down |
{Pgdn} |
| Page up |
{Pgup} |
| Print Screen |
{Prtsc} (reserved for future use) |
| Right arrow (right arrow) |
{Right} |
| Scroll lock |
{Scrolllock} |
| Tab |
{Tab} |
| Up Arrow (up arrow) |
{Up} |
| F1 |
{F1} |
| F2 |
{F2} |
| F3 |
{F3} |
| F4 |
{F4} |
| F5 |
{F5} |
| F6 |
{F6} |
| F7 |
{F7} |
| F8 |
{F8} |
| F9 |
{F9} |
| F10 |
{F10} |
| F11 |
{F11} |
| F12 |
{F12} |
| F13 |
{F13} |
| F14 |
{F14} |
| F15 |
{F15} |
| F16 |
{F16} |
| Numeric keypad plus sign |
{Add} |
| Digital keyboard minus sign |
{Subtract} |
| Numeric keypad Multiplication |
{Multiply} |
| Numeric keypad Division |
{Divide} |
To specify keys that can be used with any combination of shift, Ctrl, and ALT keys, add one or more codes before these key codes:
If you enter the Alt + Tab key combination, we can
Sendkeys. Send ("% {tab }");
To show that you should press any combination of shift, Ctrl, and ALT at the same time when pressing other keys, please put the code of those keys in brackets. For example, to demonstrate how to press the Shift key while pressing E and C, use "+ (EC )". "+ EC" is used to indicate that the shift key is pressed at the same time while the Shift key is pressed at C instead of shift ".
To specify duplicate keys, use the {key number} format. A space must be placed between the key and number. For example, {left 42} Means 42 times to press the left arrow key; {H 10} means 10 times to press the H key.
Note that you cannot use sendkeys to send a key message to an application that is not designed to run in Microsoft Windows. Sendkeys cannot send the print screen button {prtsc} to any application either.
Self-built http://archive.cnblogs.com/a/1951707/