SendKeys

concerns

The SendKeys function sends a key sequence (which can consist of one or more keystrokes) to the active window as if it had been entered using the keyboard.

 

Syntax

SendKeys(Expr [, Wait)

Return value

None

Parameter

Use

Name

Type

Passing

Description

Required

Expr

String

ByVal

Key terms for a key sequence

Required

Wait

Boolean

ByVal

If the value is False (default value), the procedure continues execution immediately after the key sequence is sent. If the value is True the key sequence must be processed before the procedure can continue to execute

 

Note

Each key is represented by at least one character. A single character on the keyboard can be specified with the character itself. For example, "A" represents the letter A. You specify multiple characters by attaching the characters to each other. For example, "ABC" represents the letters A, B and C.

The plus sign (+), the caret sign (^), the percent sign (%), the tilde (~) and the parentheses ( ) have a special meaning in the SendKeys function. You must enclose each of these characters in curly braces ({}) in order to use it. For example, for the plus sign, you specify {+}. Square brackets ([ ]) have no special meaning in the SendKeys function, but they must also be enclosed in curly braces because they have a special meaning in other applications, especially in connection with dynamic data exchange (DDE). You set the characters for the curly braces under use of {{} and {}}.

For characters that do not appear when you press a key (for example, enter or tab) and for certain action keys you can use the following codes:

Key                         Code

BACKSPACE               {BACKSPACE}, {BS} oder {BKSP}

BREAK                      {BREAK}

CAPSLOCK                {CAPSLOCK}

DEL                         {DELETE} oder {DEL}

DOWN                      {DOWN}

END                         {END}

ENTER                      {ENTER}oder ~

ESC                         {ESC}

HELP                        {HELP}

HOME                       {HOME}

INSERT                     {INSERT} oder {INS}

LEFT                        {LEFT}

NUMLOCK                  {NUMLOCK}

PGDN                       {PGDN}

PGUP                       {PGUP}

PRTSC                      {PRTSC}

RIGHT                      {RIGHT}

SCROLLLOCK             {SCROLLLOCK}

TAB                         {TAB}

UP                           {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}

 

You can specify keyboard shortcuts using SHIFT, CTRL, or ALT key by specifying one or more of the following codes before the normal key code:

Key            Code

SHIFT          +

CTRL           ^

ALT             %

 

If SHIFT, CTRL, and ALT need to be pressed at the same time as other keys, enclose the codes for the keys in parentheses. For example, if you want to press the SHIFT key at the same time with the E and C keys, specify "+(EC)". If you want to press the SHIFT key together with E and then C without SHIFT, specify "+EC".

You can specify key repetitions in the form of {Number key}. The space between the key and the number is mandatory. For example, {LEFT 42} is interpreted as pressing the AFTER-LEFT key 42 times, {h 10} as 10 times pressing the H key.

Note

SendKeys can’t send the PRTSC-KEY {PRTSC}.