SendKeys (statement)

Syntax

SendKeys KeyString$ [,[isWait] [,time]]

Description

Sends the specified keys to the active application, optionally waiting for the keys to be processed before continuing.

Comments

The SendKeys statement accepts the following parameters:

 

Parameter

Description

 

KeyString$

String containing the keys to be sent. The format for KeyString$ is described below.

 

isWait

Boolean value.

If TRUE, then the Basic Control Engine waits for the keys to be completely processed before continuing.

If you are using SendKeys in a CimEdit/CimView script, you must set this flag to TRUE. If you do not, when a user tries to execute the SendKeys statement, the CimView screen freezes and processing will not continue.

If FALSE (or not specified), then the BasicScript continues script execution before the active application receives all keys from the SendKeys statement.

 

time

Integer specifying the number of milliseconds devoted for the output of the entire KeyString$ parameter. It must be within the following range:

  0 <= time <= 32767

For example, if time is 5000 (5 seconds) and the KeyString$ parameter contains ten keys, then a key will be output every 1/2 second. If unspecified (or 0), the keys will play back at full speed.

 

Specifying Keys

To specify any key on the keyboard, simply use that key, such as "a" for lowercase a, or "A" for uppercase a.

Sequences of keys are specified by appending them together: "abc" or "dir /w".

Some keys have special meaning and are therefore specified in a special way, by enclosing them within braces. For example, to specify the percent sign, use "{%}".

the following table shows the special keys:

 

Key

Special Meaning

Example

 

+

Shift

"+{F1}"

'Shift+F1

 

^

Ctrl

"^a"

'Ctrl+A

 

~

Shortcut for Enter

"~"

'Enter

 

%

Alt

"%F"

'Alt+F

 

[]

No special meaning

"{[}"

'Open bracket

 

{}

Used to enclose special keys

"{Up}"

'Up Arrow

 

()

Used to specify grouping

"^(ab)"

'Ctrl+A, Ctrl+B

 

Keys that are not displayed when you press them are also specified within braces, such as {Enter} or {Up}. A list of these keys follows:

 

 

 

 

 

 

 

{BkSp}

{BS}

{Break}

{CapsLock}

{Clear}

 

{Delete}

{Del}

{Down}

{End}

{Enter}

 

{Escape}

{Esc}

{Help}

{Home}

{Insert}

 

{Left}

{NumLock}

{NumPad0}

{NumPad1}

{NumPad2}

 

{NumPad3}

{NumPad4}

{NumPad5}

{NumPad6}

{NumPad7}

 

{NumPad8}

{NumPad9}

{NumPad/}

{NumPad*}

{NumPad-}

 

{NumPad+}

{NumPad.}

{PgDn}

{PgUp}

{PrtSc}

 

{Right}

{Tab}

{Up}

{F1

{Scroll Lock}

 

{F2}

{F3}

{F4}

{F5}

{F6}

 

{F7}

{F8}

{F9}

{F10}

{F11}

 

{F12}

{F13}

{F14}

{F15}

{F16}

 

Keys can be combined with Shift, Ctrl, and Alt using the reserved keys "+", "^", and "%" respectively:

For Key Combination Use

Shift+Enter "+{Enter}"
Ctrl+C "^c"
Alt+F2 "%{F2}"

 

To specify a modifier key combined with a sequence of consecutive keys, group the key sequence within parentheses, as in the following example:

For Key Combination Use

Shift+A, Shift+B "+(abc)"
Ctrl+F1, Ctrl+F2 "^({F1}{F2})"

 

Use "~" as a shortcut for embedding Enter within a key sequence:

For Key Combination Use

a, b, Enter, d, e "ab~de"
Enter
, Enter "~~"

 

To embed quotation marks, use two quotation marks in a row:

For Key Combination Use

"Hello" ""Hello""
a"b"c  "a""b""c"

 

Key sequences can be repeated using a repeat count within braces:

For Key Combination Use

Ten "a" keys "{a 10}"
Two Enter keys "{Enter 2}"

Example

This example runs Notepad, writes to Notepad, and saves the new file using the SendKeys statement.

Sub Main()

   Dim id As Variant

   id = Shell ("notepad.exe")    'Run Notepad minimized

   AppActivate id                'Now activate Notepad

   AppMaximize                   'Open and maximize the Notepad window

   SendKeys "Hello Notepad", 1   'Write text with time to avoid burst

   Sleep 2000

   SendKeys "%fs", 1             'Save file (Simulate Alt+F,S keys)

   Sleep 2000

   SendKeys "name.txt{ENTER}", 1 'Enter name of file to save

   AppClose

End Sub

 

 

 

 

 

 

More information

S