Keyboard Input Emulation

SEND-KEYS: "key_code_string"

Sends one or several key codes to the active window, in other words, emulates keyboard input. Command SEND-KEYS: can be used both to use a keyboard shortcut (hotkey) in the active window (e.g. CTRL+S in order to save a file) as well as for just "typing" some text in text editors and in various input fields.

Section "Key Codes" contains detailed explanations of how to use key codes as arguments of word SEND-KEYS:


\ typing word test
SEND-KEYS: "test"
\ typing 12345 on one line and  67890 on the next one
SEND-KEYS: "12345{ENTER}67890"

Sometimes it becomes necessary to specify key codes for a keyboard shortcut consisting of two or more keys that should be pressed simultaneously (e.g. CTRL is pressed and then, while it is being held down, ALT and G are pressed too). In this case, you should first indicate the first key that is being pressed and held down, and state the remaining key codes after it in parentheses.


\ SHIFT+e+c
SEND-KEYS: "+(ec)"
SEND-KEYS: "^(+a)"
SEND-KEYS: "^(@)"
\ WIN+F1
SEND-KEYS: "$({F1})"

Pauses between individual "keystrokes" and SEND-KEYS: constructs can be set with word SEND-KEYS-DELAY:. A delay (pause) in milliseconds between two keystrokes can also be specified by using the following expression:

{DELAY time-in-ms} 


#( test_send_keys
\ typing 12345, making a one-second delay
\ and then typing 67890.
    WIN-ACTIVATE: "*Notepad"
    SEND-KEYS: "12345{DELAY 1000}67890"
#( test_send_keys1
\ starting Calculator and making some simple calculations. Time: 0 12 * * * * Action: START-APP: calc.exe PAUSE: 500 WIN-ACTIVATE: "Calculator" PAUSE: 100 SEND-KEYS: "1{+}2{ENTER}{DELAY 2000}*3{ENTER}" )#

Using SEND-KEYS:, you can even switch the keyboard layout and type in several installed input languages. Notice, please, that you should watch the active keyboard layout for currently active GUI-application when typing in alternative languages. If standard (EN) keyboard layout was active before SEND-KEYS: usage, you can emulate typing of your native letters just by switching the keyboard layout and using the corresponding latin letters as an argument for SEND-KEYS:

\ 'EN' is the active keyboard layout.
\ We are using 'ALT+SHIFT' to switch the keyboard layout.
WIN-ACTIVATE: "*Notepad"
PAUSE: 500
SEND-KEYS: "+(t)est @(+)ntcn @(+)test"  

If the alternative keyboard layout was active prior to SEND-KEYS: usage, you should use your native characters as an argument to SEND-KEYS:

\ 'RU' is the active keyboard layout.
\ We are using 'ALT+SHIFT' to switch the keyboard layout.
WIN-ACTIVATE: "*Notepad"
PAUSE: 500
SEND-KEYS: "+(t)est @(+)тест @(+)test"  

Thus, you can define a task like this:

#( test_typing
\ setting keyboard layout to 'RU'
: KeysToRUS SEND-KEYS: "@(+1)" ;
\ setting keyboard layout to 'EN'
: KeysToENG SEND-KEYS: "@(+2)" ;
   PAUSE: 1000
   SEND-KEYS: "+(Э)то тест - " 
   SEND-KEYS: "This is a test" 

You can determine the active keyboard layout for GUI-application using the kbd_layout.spf plugin.

Limitations: You cannot use key PrtScr (PRINTSCREEN) in keyboard shortcuts. Besides, you won't be able to use SEND-KEYS: to "press" CTRL+ALT+DELETE.

SEND-KEYS-DELAY: <between_keystrokes_in_ms> <between_SEND-KEYS_in_ms>

Sets delay (in milliseconds) after each "keystroke" and after each subsequent SEND-KEYS: (WIN-SEND-KEYS:) construct. Allows to emulate "slow typing".

Affects all the subsequent SEND-KEYS: (WIN-SEND-KEYS:) constructs within current task.


#( test_send_keys_delay
    START-APP: notepad.exe
    1000 PAUSE
    WIN-ACTIVATE: "*Notepad"
    500 PAUSE
    SEND-KEYS-DELAY: 500 0
    SEND-KEYS: "Typing slowly..."

See also: