You can send keystrokes to an application by using a script.
To send keystrokes to an application, you must::
Identify and activate the application's window. This brings the window to the foreground and enables it to accept keystrokes. adTempus provides two functions for doing this (ActivateWindowWithTitle and ActivateWindowWithHandle), or you may use your own approach.
Send the keystrokes. The WshShell object (exposed by the Windows Script Host) offers a SendKeys method, which can be used to do this. See the SendKeys Syntax topic for more information.
All of the solutions described here use the SendKeys method. This method cannot target a specific application or window—it just sends the keystrokes to whatever window is active. Therefore you must make sure you have activated the appropriate window first, or you will be sending keystrokes to the wrong application. |
The approach will vary depending on the circumstances, as described in the following sections.
A common situation is where you have launched an application using a Program Execution task, and then need to send keystrokes to the application to tell it to run a macro or do whatever processing is necessary.
In this case the simplest approach is to create a Script Action attached to the appropriate event. For example, if you want to send the keystrokes immediately after the application is started, attach the action to the step's "Task started" event.
To send the keystrokes, just use the SendKeysToTargetApplication function defined in the Builtin script library. This function activates the correct window and sends the keystrokes.
Note that this approach can only be used within a step that executes a Program Execution Task; the SendKeysToTargetApplication function will not work in any other circumstances.
To send keystrokes to an application that was not started by an adTempus Program Execution task (or to an application that was started with a Program Execution task, but not within the current step) you can use a Script Action or a Script Execution Task to execute the script at the appropriate time.
To send keystrokes to the application you will need to know its title—the exact title that appears in the window's title bar. Then use the SendKeysToWindow function defined in the Builtin script library. This function activates the correct window and sends the keystrokes.