Send Keystrokes Action Icon

Send Keystrokes

 

Declaration

<AMSENDKEY DELAYBETWEENKEYS="number" DOS="yes/no" STAYFOCUSED="yes/no" LOCKKEYBOARD="yes/no" PREDELAY="number">text(to send) </AMSENDKEY>

See Also

Check | Click Mouse | Get Selected List Item | Get Selected Tree Item | Get Text | Hold Down Key | Move Mouse | Move Mouse to Object | Press | Release Key | Select Item | Select List Item | Select Tree Item | Set Text

Description

Sends the keystrokes to the currently focused (front) window. Keystrokes can either be sent one-by-one using the Simulate Keypress option (use when selecting buttons or menu items) or can be pasted all at once using the Paste Characters option (use when typing large amounts of text such as the body of an e-mail message). Special keystrokes such as ALT, CTRL, and SHIFT can be selected from the Special Keystrokes button and will only work when the Simulate Keypress option is selected.

Practical Usage

Send Keystrokes is one of the most commonly used actions in AutoMate. It is used primarily to simulate keystrokes being typed into an application. For example the first step in a task could be to open the application using the Run action, the next would be Send Keystrokes, which could send the keystroke "ALT-f r" to activate the file menu in the Application and select the Properties menu option.

Parameters

General Properties

Property

Type

Req'd

Default

Markup

Description

Method

Text (options)

Yes

Simulate Keypress

  1. METHOD="keypress"

  2. METHOD="paste"

The manner by which the keystrokes should be sent. The available options are:

  • Simulate Keypress - The keystrokes will be typed into the application one by one and generate key press events on the system. Use this option to click buttons, select menu options and activate accelerator and shortcut keys in an application.

  • Paste Characters - The characters will be "pasted" into the application all at once using the Windows clipboard. Existing Clipboard contents will remain intact. Use this option to send large chunks of text into an application. Since all of the characters are inserted at one time, this will substantially speed up task execution.

NOTE:The paste option is not able to select menus, buttons or other controls, it can only work in text fields.

Keystrokes

Text

Yes

(Empty)

...>The keys to send.</AMSENDKEY>

Indicates the keystrokes to send to the currently focused application. For alpha-numeric characters, the literal keystrokes that AutoMate should send should be specified. Case is preserved, so to send the value "Steve", it is not necessary to enter the code for the shift key. You can simply enter "Steve" (without quotes of course).

A Special Keystrokes button is provided for easy selection of special keys such as ALT, SHIFT and function keys. For details on how to use special keystrokes such as ALT, SHIFT, function keys, the number-pad and more, see the Notes section below.

Transpose special keystrokes as you type

Yes/No

No

No

NONE (visual interface only)

If enabled, causes all keystrokes to be taken literally in the Keystrokes parameter. This is a design time parameter and therefore contains no markups.

Special Keystrokes (button)

Text

No

(Empty)

...>The keys to send {ALT}f.</AMSENDKEY>

Provides for easy selection of special keys such as ALT, SHIFT and function keys. For details on how to use special keystrokes such as ALT, SHIFT, function keys, the number-pad and more, see the Notes section below.

Advanced Properties

Property

Type

Required

Default

Markup

Description

Add a pause before Sending/pasting keys

Number

No

100

PREDELAY="200"

The amount of time (in milliseconds) to wait when this step executes before actually sending the keystrokes. This is set to 100 milliseconds by default to give the application time to be ready to receive input before the keystrokes are sent. Although the fact that the Run Action can wait until the application is ready for input before continuing - a small delay may still be required here and may need to be adjusted according to the specific application and overall system speed.

Add a delay between individual keystrokes

Text

No

25

DELAYBETWEENKEYS="250"

The amount of time (in milliseconds) to wait between each keypress. This is set to 25 milliseconds by default to give the application time to process each keystroke before AutoMate moves to the next key. The default setting should be acceptable for most applications and system speeds.

Keep Current Foreground Window Focused

Yes/No

No

No

STAYFOCUSED="YES"

If enabled, specifies that the window that is currently at the front when the step starts should be re-focused before sending each keystroke. This prevents users from changing the focus during execution of the step. This parameter is disabled by default.

Lock Keyboard and Mouse

Yes/No

No

No

LOCKKEYBOARD="YES"

If enabled, specifies that the mouse and keyboard should be locked during the execution of the step so that a user cannot interfere with the keystrokes being sent. The mouse and keyboard are automatically unlocked when the step is finished. This parameter is disabled by default.

Use DOS Keystrokes

Yes/No

No

No

DOS="YES"

This parameter should be enabled if sending keystrokes to a windowed DOS application as keystrokes are handled differently in DOS. This parameter is disabled by default.

Encrypt Keystrokes

Yes/No

No

No

N/A

If enabled, keystrokes are masked in the task file using 128-bit encryption. This parameter is disabled by default.

Custom Description

This action includes the Description tab for entering a custom step description.

More on setting custom step description

Standard Error Handling Options

This action also includes the standard Error Causes and On Error failure handling options/tabs.

More on Error Handling Options

 Notes

Usage Notes for Keystrokes when "Simulate Keypress" Mode is Enabled

NOTE: The following information is only valid when the Method parameter is set to the default Simulate Keypress. Since special keys cannot be pasted, this information is not relevant when the Paste characters parameter is specified.

 

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. If you want to represent more than one character, append each additional character to the one preceding it. To represent the letters A, B, and C, use ABC. To send a space, simply press the space bar. The plus sign +, caret ^, percent sign %, tilde ~, and parentheses ( ) have special meanings. To specify one of these characters, enclose it within braces. For example, to specify the plus sign, use {+}. Brackets [ ] have no special meaning, but you must enclose them in braces as well, because in other applications, brackets do have a special meaning that may be significant. To send brace characters, use {{} and {}}. To specify characters that aren't displayed when you press a key (such as ENTER or TAB) and keys that represent actions rather than characters, use the codes shown below:

Primary Key Codes

To specify keys combined with any combination of the SHIFT, CTRL, and ALT keys, precede the regular key code with one or more of the following codes:

ALT = {ALT}

CTRL = {CTRL}

SHIFT = {SHIFT}

ALTGr = {ALTGR}

Holding Keys Down at the Same Time

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 holding down SHIFT while "e" and "c" are pressed (e and c keys are "mated"), use {SHIFT}(ec). To specify holding down SHIFT while "e" is pressed, followed by c without SHIFT, use "{SHIFT}ec".

Repeating Keys

To specify repeating keys, use the form {key code number}. You must put a space between key and number. For example, {LEFT 42} means press the LEFT ARROW key 42 times; {h 10} means press h 10 times.

Other Key Codes

The following table lists other valid key codes you can use to simulate keypress.

To simulate...

Enter...

BACKSPACE

{BACKSPACE}, {BS}, or {BKSP}

BREAK

{BREAK}

CAPS LOCK

{CAPSLOCK}

CAPS LOCK On

{CAPSON}

CAPS LOCK Off

{CAPSOFF}

DEL

{DELETE} or {DEL}

END

{END}

ENTER

{ENTER} or ~ or (press the enter key)

ESC

{ESC}

HELP

{HELP}

HOME

{HOME}

INSERT

{INSERT}

NUM LOCK (toggle)

{NUMLOCK}

NUM LOCK On

{NUMLOCKON}

NUM LOCK Off

{NUMLOCKOFF}

PAGE DOWN

{PGDN}

PAGE UP

{PGUP}

PRINT SCREEN

{PRTSC}

SCROLL LOCK (toggle)

{SCROLLLOCK}

SCROLL LOCK Off

{SCROLLLOCKOFF}

SCROLL LOCK On

{SCROLLLOCKON}

TAB

{TAB}

UP ARROW

{UP}

DOWN ARROW

{DOWN}

RIGHT ARROW

{RIGHT}

LEFT ARROW

{LEFT}

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}

Number Pad 0

{NUMPAD0}

Number Pad 1

{NUMPAD1}

Number Pad 2

{NUMPAD2}

Number Pad 3

{NUMPAD3}

Number Pad 4

{NUMPAD4}

Number Pad 5

{NUMPAD5}

Number Pad 6

{NUMPAD6}

Number Pad 7

{NUMPAD7}

Number Pad 8

{NUMPAD8}

Number Pad 9

{NUMPAD9}

Number Pad /

{NUMPAD/}

Number Pad *

{NUMPAD*}

Number Pad -

{NUMPAD-}

Number Pad +

{NUMPAD+}

Number Pad .

{NUMPAD.}

Number Pad Separator

{NUMPADSEP}

Windows Key

{WINKEY}

Popup Menu Key

{POPUP}

Press and release ALT

{QUICKALT}

Press and release CTRL

{QUICKCTRL}

Press and release SHIFT

{QUICKSHIFT}

Variables and Expressions

All text fields allow the use of expressions, which can be entered by surrounding the expression in percentage signs (example: %MYVARIABLE%, %Left('Text',2)%). To help construct these expressions, you can open Expression Builder from these fields by pressing F2.

More on variables
More on expressions
More on the expression builder

Example

NOTE: The code below can be copied and pasted directly into the Steps pane of the Task Builder.

 

Sample Task 1 - This sample task illustrates how the Send Keystrokes action sends keys via the Paste Characters method and the Send Keypress method.

 

<AMRUN FILE="Notepad" />

<AMSENDKEY METHOD="paste" PREDELAY="1000">Keystrokes can be pasted like this.</AMSENDKEY>

<AMSENDKEY DELAYBETWEENKEYS="100" STAYFOCUSED="YES" PREDELAY="1000">

Or they can simulate key presses like this. </AMSENDKEY>

 

 

Sample Task 2 - This sample task demonstrates use of the Create Variable, Format Date Time, Run, Send Keystrokes, and Pause actions. It simply opens Notepad and sends keystrokes to it in regards to when the task started and when it ended.

 

<AMVARIABLE NAME="TheStartDateTime"></AMVARIABLE>

<AMVARIABLE NAME="theEndDateTime"></AMVARIABLE>

<AMTEXTFORMATDATETIME DATETIMEFORMAT="mm/dd/yyyy h:nn:ss" RESULTVARIABLE="TheStartDateTime" />

<AMTEXTFORMATDATETIME DATETIMEFORMAT="mm/dd/yyyy h:nn:ss" RESULTVARIABLE="theEndDateTime" />

<AMRUN FILE="C:\Sample_Stop_Start_Task.txt" DEFAULTFOLDER="C:" />

<AMSENDKEY>The task started at %TheStartDateTime%&#xD;&#xA;</AMSENDKEY>

<AMPAUSE ACTION="waitfor" SCALAR="3" />

<AMSENDKEY>The task ended at %theEndDateTime%

</AMSENDKEY>

<AMPAUSE SCALAR="2" />

<AMSENDKEY DELAYBETWEENKEYS="200">{ALT}fxy</AMSENDKEY>

 

↑ Top of Page