Input
- Send keystrokes
Declaration
<AMINPUT KEYSTROKES="text" METHOD="text (options)" PREDELAY="number" STAYFOCUSED="YES/NO" DELAYBETWEENKEYS="number" LOCKKEYBOARD="YES/NO" DOS="YES/NO" />
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 |
|
The
keystrokes to perform. The
available options are:
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
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 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. |
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
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:
Example
- 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.
<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.
<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" />