Send Keystrokes Method
The Send Keystrokes method sends keystrokes to an active Microsoft Windows application. It does not return a value. It can send a keystroke only to the currently active application. You can use the AppActivate statement to activate an application. You cannot use this method to send keys to an application that does not run in Microsoft Windows.
Format
SendKeys string[, wait]
The following table describes the arguments that you can use with this method.
Argument | Description |
---|---|
string |
A string or string expression that contains the characters to send. Each character in the string argument represents a keystroke. |
wait |
Specifies to wait until Siebel VB processes every key before it continues to the next code line. It can include one of the following values:
|
Specifying Alphanumeric Characters
To specify an alphanumeric character, you enter it in the string argument. For example, to send the character a, you use a as the value in the string argument. You can combine multiple characters in one string. For example, if the string argument contains abc, then Siebel VB sends the following values to the application:
a, b, and c
Specifying Control Keys
To specify that the user must press the SHIFT, ALT, or CTRL key simultaneously with a character, you prefix the character with one of the following values:
-
+. Specifies SHIFT.
-
%. Specifies ALT.
-
^ . Specifies CTRL.
You can use parentheses to specify that the user must press the SHIFT, ALT, or CTRL key with a group of characters. For example, %(abc) is equivalent to %a%b%c.
Control Keys That the Send Keystrokes Method Interprets
The following table describes some keys that the Send Keystrokes method interprets. To specify one of these characters as a literal value, you must enclose the character in curly brackets ({}).
Key | Description |
---|---|
+ |
SHIFT key. |
% |
ALT key. |
^ |
CTRL key. |
( ) |
Apply a shift state to the characters that the parentheses enclose. |
~ |
Newline. Note the following:
|
{ } |
Makes the enclosed characters literals. |
[ ] |
Square brackets do not possess a special meaning for the Send Keystrokes method, but they might possess a special meaning for other applications. |
For example, if the string argument contains {%}, then the Send Keystrokes method sends the literal value of the percentage symbol (%).
You can use the following format to send a bracket:
-
Left bracket. You use {{}.
-
Right bracket. You use {}}.
Repeating the Same Key
To send the same key multiple times, you can enclose the character in curly brackets ({}), add a space, and then specify the number of keys to send. For example, the following code sends 20 X characters:
{X 20}
Sending Nonprintable Keys
The following table describes how you can to send a nonprintable key. You can use a special keyword and enclose it in curly brackets ({}).
Nonprintable Key | Format |
---|---|
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} |
Function key (F1 through F15) |
You enclose the name of the function key in curly brackets ({}). For example, to send F5, you use the following format: {F5} |
Combining Keywords
You can use the following characters to combine some keywords:
-
Plus sign (+)
-
Percentage symbol (%)
-
Caret (^)
For example, %{TAB} is ALT+TAB.
You can send multiple keywords. For example, the following code sends 25 up arrows:
{UP 25}
Example
The following example starts the Microsoft Windows Phone Dialer application and dials a phone number that the user enters:
Sub Button_Click
Dim phonenumber, msgtext
Dim x
phonenumber = 650-555-1212
x = Shell ("Terminal.exe",-1)
SendKeys "%N" & phonenumber & "{Enter}", -1
End Sub