Sendkeys

Send one or more keystrokes to the active window as if typed at the keyboard.

Syntax
      SendKeys string[, wait]

Key
   string 	 String expression specifying the keystrokes to send.

   Wait     Boolean value specifying the wait mode.

            If False (default), control is returned to the
            procedure immediately after the keys are sent.
            If True, keystrokes must be processed before control
            is returned to the procedure.

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, use "A" for string.

A string of characters can be sent: e.g. "SS64"

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:

 SHIFT  +
 CTRL   ^
 ALT    %

Character codes for other keyboard characters:

 BACKSPACE {BACKSPACE}, {BS}, or {BKSP} 
 BREAK     {BREAK}
 CAPS LOCK {CAPSLOCK}
 DEL or DELETE {DELETE} or {DEL}
 END   {END}
 ENTER {ENTER} or ~
 TAB   {TAB}
 ESC   {ESC}
 HELP  {HELP}
 HOME  {HOME}
 INS or INSERT {INSERT} or {INS}
 DOWN ARROW  {DOWN}
 LEFT ARROW  {LEFT}
 RIGHT ARROW {RIGHT}
 UP ARROW    {UP}
 NUM LOCK 	  {NUMLOCK}
 SCROLL LOCK {SCROLLLOCK}
 PAGE DOWN   {PGDN}
 PAGE UP {PGUP}
 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}

The plus sign +, caret ^, percent sign %, tilde ~, and parentheses ( and ) have special meanings to SendKeys. To specify one of these characters, enclose it within braces: {+}

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

To specify repeating keys, use the form

{key number}

The SendKeys() statement may be used in VBA.

Examples

'Send the string SS64 to the active application:
SendKeys "SS64"

'Press Control and F2 in the active application:
SendKeys ^{F2}

'press the LEFT ARROW key 42 times:
SendKeys {LEFT 42}

“Begin at the beginning, the King said, very gravely, and go on till you come to the end: then stop” ~ Lewis Carroll

Related:

SetFocus - Move the focus to a specific control on a form.


© Copyright SS64.com 1999-2013
Some rights reserved