Note: in Windows 8 / 7 / Vista, this won't work on a UAC prompt and related credentials box.
// Optionally go to other field:
SomeOtherField.Focus();
// Add string at insertion point / over selected text:
SendKeys.Send("This is a test..."); The Send() method processes the string you passed immediately; to wait for a response from the program (like auto-populated database records matching input), use SendWait() instead.| TOP ROW | |
|---|---|
| Escape | {ESC} |
| Function Keys | {F1} ... {F16} |
| Print Screen | {PRTSC} |
| Break | {BREAK} |
| Help | {HELP} (Depending on active app, could be F1 or Ctrl+F1) |
| LOCK KEYS | |
| Caps lock | {CAPSLOCK} |
| Num Lock | {NUMLOCK} |
| Scroll Lock | {SCROLLLOCK} |
| NAVIGATION AND EDITING KEYS | |
| Tab | {TAB} |
| Backspace | {BACKSPACE}, {BS}, or {BKSP} |
| Validation | {ENTER} or ~ (a tilde) |
| Ins Or Insert | {INSERT} or {INS} |
| Delete | {DELETE} or {DEL} |
| Text Navigation | {HOME} {END} {PGDN} for Page Down {PGUP} for Page Up |
| Arrow Keys | {UP} {RIGHT} {DOWN} {LEFT} |
| NUMERIC OPERATOR KEYS (on keypad side, not numpad) | |
| Keypad Add | {ADD} |
| Keypad Subtract | {SUBTRACT} |
| Keypad Multiply | {MULTIPLY} |
| Keypad Divide | {DIVIDE} |
| MODIFIER KEYS | |
| Shift | + |
| Control (Ctrl) | ^ |
| Alt | % |
SendKeys.Send("{ENTER}");
// Or this:
SendKeys.Send("~");// Go up 7 lines in a text area:
SendKeys.Send("{UP 7}");
// To type three times the letter 'w':
SendKeys.Send("{w 3}");// Let us "Save As" in a classic-menu program with Alt+F,A
SendKeys.Send("%(FA)");
// Let's make text bold and type an "A": Ctrl+B, release, A
SendKeys.Send("^BA"); Note: modifier keys combinations (like Ctrl+Alt+Delete) will not have the expected result.