SendKeys

Windows management function.

The SendKeys function sends keyboard characters to the window specified by the most recent UseWindow.

Usage

SendKeys function is used primarily to simulate keystrokes being typed into an application. For instance, the first line in a script could be to open the application using Shell function, the next step would be a SendKeys to send keystrokes. Before the SendKeys line, a UseWindow statement would specify the window where the keystrokes have to be sent.

Syntax

SendKeys(<key_list> [,NoActivate])
or
ret=SendKeys(<key_list> [,NoActivate])

Parameters

<key_list>, string of characters ; each special key has a keyword for the Sendkeys function. See Keyboard mnemonics. To send a space, use " " (with a space between the double quotes). If no active Window is found or if an error is found in <key_list>, an error message is displayed and all the scripts are stopped (depending on #IgnoreErrors value, see Error handling).

Noactivate : optional keyword. It is used for sending keys to the window which has the focus without checking that it's the one defined in the most recent UseWindow. This keyword is useful to send keystrokes to different fields in a form : instead of a UseWindow line for each individual field in the form, you can use only one, and then you fill the different fields using SendKeys with Noactivate parameter, and you use a SendKeys("<Tab>",Noactivate) to go from one field to another.

Return value

Ret, numeric return code. When SendKeys is successful, the function returns 0, otherwise use this return code for Error Handling.

Remarks

The variable #SendKeysDelay (set to 0 by default) slows down the typing of characters. A small delay is added between each typed scan code (for "a<Ctrl A>, there will be a delay between a, Ctrl and A).

Sendkeys function is not able to send some non-English characters (for instance, the ñ character in Spanish), see Sendkeys with non-English characters if you need to type some non-English or not-French characters which are not recognized by SendKeys.

SendKeys function cannot send as is keyboard mnemonics such as <Alt <Enter>>, you need to use the keyboard mnemonics for the string to send, "normal text"+"<Alt <Enter>>"+"normal text".

Examples

In recording mode:

UseWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
SendKeys("Hello")

SendKeys("<Enter>")

SendKeys("Hello<Enter><Alt <F5>>")

Variables can be used:

 

UseWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
a$="Hello"
SendKeys(a$)