Input - Send keystrokes

Declaration

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

Related Topics

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

Used primarily to simulate keystrokes being typed into a program, application or similar window. For example, after using the Run action to start an application, this activity can send keystrokes "ALT-f" to activate the file menu in the application.

Parameters

General

Property

Type

Required

Default

Markup

Description

Method

Text (options)

Yes

Simulate Keypress

  1. METHOD="keypress"

  2. METHOD="paste"

  3. METHOD="text"

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 or key-down 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.

  • Low Level Input - Certain applications such as Remote Desktop may have difficulty detecting keystrokes sent using the normal Simulate Keypress method. The Low Level Input option uses a simple .NET method to send keystrokes using the Win32 'SendInput' method, which solves a majority of keystrokes capturing issues.

NOTE: The Paste Characters option cannot perform operations such as selecting menus, buttons or other controls. It is designed to work only 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)

Special Keystrokes (button)

Text

No

(Empty)

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

Enables easy selection of special keys such as ALT or SHIFT as well as function, arrow and keypad keys (i.e. for the purpose of console control handler functionality). For more details, see Additional Notes below.

NOTE: For details about Console Control Handlers and how to properly automate the use of special keys, see the Additional Notes section below.

Transpose special keystrokes as you type

---

---

---

---

If enabled, causes all keystrokes entered under the Keystrokes parameter to be taken literally (disabled by default).This is a design time parameter and therefore contains no markups.

Encrypt keystroke content

---

---

---

---

If enabled, causes all keystrokes entered under the Keystrokes parameter to be encrypted. Encrypted keys are masked in the task file using 128-bit encryption If disabled, the keystrokes will be displayed in plane text (disabled by default). This is a design time parameter and therefore, contains no markups.

Advanced

Property

Type

Required

Default

Markup

Description

Before keystrokes, delay (milliseconds)

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.

Between keystrokes, delay (milliseconds)

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 foreground window focused

Yes/No

No

No

STAYFOCUSED="YES"

If set to YES, specifies that the window that is currently in the foreground (at the front of all other windows) should be re-focused before the step starts sending keystrokes in order to prevent users from accidentally changing the focus during execution. This parameter is set to NO by default.

Lock keyboard and mouse

Yes/No

No

No

LOCKKEYBOARD="YES"

If set to YES, specifies that the mouse and keyboard should be locked during execution of this step in order to prevent users from interfering with the keystrokes being sent. The mouse and keyboard are automatically unlocked upon completion of this step. This parameter is set to NO by default.

Use DOS Keystrokes

Yes/No

No

No

DOS="YES"

This parameter should be enabled if sending keystrokes to a DOS (command prompt) window 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.

 

Description

Error Causes

On Error

additional Notes

Console Control Handlers

The CTRL+C and CTRL+BREAK key combinations receive special handling by console processes. By default, when a console window has the keyboard focus, CTRL+C or CTRL+BREAK is treated as a signal (SIGINT or SIGBREAK) and not as keyboard input. By default, these signals are passed to all console processes that are attached to the console. (Detached processes are not affected.) The system creates a new thread in each client process to handle the event. The thread raises an exception if the process is being debugged. The debugger can handle the exception or continue with the exception unhandled.

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

NOTE: The following information is only valid when the Simulation method parameter is set to Simulate keystrokes. Since special keys cannot be pasted, this information is not relevant when the Paste characters option 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:

To simulate...

Enter...

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}

Example

NOTE: The sample AML code below can be copied and pasted directly into the Steps panel 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