Siebel VB Language Reference > VB Language Reference >

SendKeys Statement


This standard VB statement sends keystrokes to an active Windows application.

Syntax

SendKeys string[, wait]

Argument
Description

string

A string or string expression containing the characters to send

wait

An integer expression specifying whether to wait until every key is processed before continuing program execution, where:

  • -1 = wait
  • 0 = don't wait
Returns

Not applicable

Usage

The keystrokes are represented by characters of string.

The default value for wait is 0 (FALSE).

To specify an alphanumeric character, enter it in string. For example, to send the character a, use a as string. Several characters can be combined in one string: If string is abc, then a, b, and c are sent to the application.

To specify that the SHIFT, ALT, or CTRL key should be pressed simultaneously with a character, prefix the character with

+

to specify SHIFT

%

to specify ALT

^

to specify CTRL

Parentheses can be used to specify that the SHIFT, ALT, or CTRL key should be pressed with a group of characters. For example, %(abc)is equivalent to %a%b%c.

The following characters must be enclosed in braces if they are to be understood as literal characters by SendKeys; otherwise they have specific meanings as follows:

+

SHIFT key

%

ALT key

^

CTRL key

( )

Apply a shift state to the enclosed characters

~

Newline. Use "~" for the ENTER key on the alphanumeric keyboard, and use "{Enter}" for the ENTER key on the numeric keypad

{ }

Used to make the enclosed characters literals

[ ]

No special meaning for SendKeys, but may have special meaning in other applications

For example, a string equal to {%} specifies a literal percent character, %.

Use {{} to send a left brace and {}} to send a right brace.

To send the same key several times, enclose the character in braces and specify the number of keys sent after a space. For example, use {X 20} to send 20 X characters.

To send one of the nonprintable keys, use a special keyword inside braces:

Key
Keyword

BACKSPACE

{BACKSPACE} or {BKSP} or {BS}

BREAK

{BREAK}

CAPS LOCK

{CAPSLOCK}

CLEAR

{CLEAR}

DELETE

{DELETE} or {DEL}

DOWN ARROW

{DOWN}

END

{END}

ENTER (on numeric keypad)

{ENTER}

ESC

{ESCAPE} or {ESC}

HELP

{HELP}

HOME

{HOME}

INSERT

{INSERT}

LEFT ARROW

{LEFT}

NUM LOCK

{NUMLOCK}

PAGE DOWN

{PGDN}

PAGE UP

{PGUP}

RIGHT ARROW

{RIGHT}

SCROLL LOCK

{SCROLLLOCK}

TAB

{TAB}

UP ARROW

{UP}

To send one of the function keys (F1 to F15), simply enclose the name of the key inside braces. For example, to send F5, use {F5}.

Note that special keywords can be used in combination with +, %, and ^. For example, %{TAB} means ALT+TAB. Also, you can send several special keys in the same way as you would send several normal keys: {UP 25} sends 25 up arrows.

SendKeys can send keystrokes only to the currently active application. Therefore, you have to use the AppActivate statement to activate an application before sending keys (unless it is already active).

SendKeys cannot be used to send keys to an application that was not designed to run under Windows.

Example

This example starts the Windows Phone Dialer application and dials a phone number entered by the user.

Sub Button_Click
   Dim phonenumber, msgtext
   Dim x
   phonenumber = 650-555-1212
   x = Shell ("Terminal.exe",-1)
   SendKeys "%N" & phonenumber & "{Enter}", -1
End Sub

Related Topics

Shell Function

Siebel VB Language Reference Copyright © 2006, Oracle. All rights reserved.