Input - Send keystrokes

Declaration

<AMINPUT KEYSTROKES="text" METHOD="text (options)" PREDELAY="number" STAYFOCUSED="YES/NO" DELAYBETWEENKEYS="number" LOCKKEYBOARD="YES/NO" DOS="YES/NO" />

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 email 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 keystrokes
  • METHOD="paste"
  • METHOD="text"
The keystrokes to perform. The available options are:
  • Simulate keystrokes - 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 keystrokes 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 keystrokes to send. Indicates the keystrokes to send to the currently focused application. For alpha-numeric characters, specify the keystrokes for Automate Desktop to send. Letter case is preserved in most scenarios, so to send the value "Steve", the Shift key code is not required.
NOTE: If your Caps Lock key on your keyboard is pressed, all keystrokes are changed to upper-case, regardless of the case used in this parameter. To override the Caps Lock key, include the CAPS LOCK On or CAPS LOCK Off key codes in your task to turn Caps Lock on or off.
Special keystrokes (button) Text No (Empty) {CTRL-ALT-DEL} Enables easy selection of special keys such as ALT or SHIFT as well as function, arrow and keypad keys (that is, 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 --- --- --- --- 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 Desktop 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 selected, 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 disabled by default.
Lock keyboard and mouse Yes/No No No LOCKKEYBOARD="YES" If selected, 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 disabled 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.

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 the "h" key 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:
  • Copy and paste the sample AML code below directly into the Task Builder Steps Panel.
  • To successfully run the sample code, update parameters containing user credentials, files, file paths, or other information specific to the task to match your environment.

Example 1

This sample task illustrates how the Send Keystrokes action sends keys by way of the Paste Characters method and the Send Keypress method.

Copy
<AMRUN FILE="Notepad" />
<AMINPUT KEYSTROKES="Keystrokes can be pasted like this" METHOD="paste" PREDELAY="1000" />
<AMINPUT KEYSTROKES="Or they can simulate key presses like this." PREDELAY="1000" STAYFOCUSED="YES" DELAYBETWEENKEYS="100" />

Example 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.

Copy
<AMVARIABLE NAME="TheStartDateTime" VALUE="" />
<AMVARIABLE NAME="theEndDateTime" VALUE="" />
<AMTEXT ACTIVITY="format_datetime" RESULTVARIABLE="TheStartDateTime" DATETIMEFORMAT="MM/dd/yyyy H:mm:ss" />
<AMTEXT ACTIVITY="format_datetime" RESULTVARIABLE="theEndDateTime" DATETIMEFORMAT="MM/dd/yyyy H:mm:ss" />
<AMRUN FILE="C:\Sample_Stop_Start_Task.txt" DEFAULTFOLDER="C:" />
<AMINPUT>The task started at %TheStartDateTime%</AMINPUT>
<AMWAIT SCALAR="3" />
<AMINPUT>The task ended at %TheEndDateTime%</AMINPUT>
<AMWAIT SCALAR="2" />
<AMINPUT KEYSTROKES="{ALT}fxy" DELAYBETWEENKEYS="200" />