keys(string format, ...)

Sends key strokes and mouse clicks to the active window or dialog. This way a script can 'remote control' other external programs, f.i. for placing orders in the window of a trade software.

Parameters:

format - string containing the key characters to be sent, in the same format as in printf. Within the string, the following tokens in square barackets have a special meaning:

[Ctrl-] - the following character is sent together with the [Ctrl]-key.
[Alt-]  - the following character is sent together with the [Alt]-key.
[Shift-] - the following character is sent together with the [Shift]-key.
[Win-] - the following character is sent together with the [Window]-key.
[Click x,y] - mouse click on the spot given by the x,y coordinates relative to the window's upper left corner.
[...]   - special function keys, such as [enter], [tab], [del], [f1] etc. are given in square brackets. Use [cur], [cul], [cuu], [cud] for the cursor keys.
[]], [[] - the right and left square bracket can be given in square brackets.

Remarks:

Example:

// Opens Notepad, writes something, saves it, and closes Notepad.
function main()
{
// start Notepad before 
   while(!window("Editor")) wait(100);  // wait until Notepad is open
   keys("Zorro is cool!"); // write something
   keys("[Ctrl-]s");               // open Save dialog (Ctrl-S) 
   while(!window(NULL)) wait(100);      // wait until the dialog window is open
   keys("cool.txt[Enter][Alt-][F4]"); // save as "cool.txt", and exit (Alt-F4)
}

See also:

exec, window, mouse

► latest version online