Keyboard functions#
Functions to type text and press keys, for when a macro needs to fill in a form or use keyboard shortcuts on the page.
Keys and text go to the element that has focus, so click the input field first. For the K_* key
codes and the WITH_* combinations, see Key constants.
Typing#
Types a string into the element that has focus, one character at a time, like a person typing. The function does not set focus itself: if you have not clicked the input field, the text lands somewhere else.
Parameters
| Name | Description |
|---|---|
text |
The string to type. |
speed1 |
Shortest pause between two characters, in milliseconds. Default 0. |
speed2 |
Longest pause between two characters, in milliseconds; each pause is a random length between speed1 and speed2. If it is smaller than speed1, every pause is exactly speed1. Default 0. |
Examples
Note
If both speed1 and speed2 are 0, the whole string is typed in one burst, which does not look
like a person typing. Set a pause of a few tens to a few hundred milliseconds.
SendKeyPress#
Presses and releases a key on the element that has focus, for example Enter to submit a form or Ctrl + V to paste.
Parameters
| Name | Description |
|---|---|
keyCode |
Key code: a K_* constant, for example K_ENTER, K_KEYA (see Key codes). It must be a number: if you pass a string such as "a", the function presses nothing. To send a character, use SendKeyChar or Typing. |
modifiers |
Keys held down at the same time: add up the constants WITH_ALT, WITH_CTRL, WITH_COMMAND, WITH_SHIFT (see Key constants). Default 0. |
Examples
SendKeyDown#
Presses and holds a key without releasing it. Release the key with SendKeyUp, using
the same keyCode and modifiers.
Parameters
| Name | Description |
|---|---|
keyCode |
Key code: a K_* constant, for example K_KEYA (see Key codes). It must be a number; if you pass a string, the function does nothing. |
modifiers |
Keys held down at the same time: add up the constants WITH_ALT, WITH_CTRL, WITH_COMMAND, WITH_SHIFT (see Key constants). Default 0. |
Example
SendKeyUp#
Releases a key, usually after SendKeyDown.
Parameters
| Name | Description |
|---|---|
keyCode |
Key code: a K_* constant, for example K_KEYA (see Key codes). It must be a number; if you pass a string, the function does nothing. |
modifiers |
Keys held down at the same time: add up the constants WITH_ALT, WITH_CTRL, WITH_COMMAND, WITH_SHIFT (see Key constants). Default 0. |
Example
SendKeyChar#
Sends one character to the element that has focus, as if typed, without key down and key up events.
To type a whole string, use Typing.
Parameters
| Name | Description |
|---|---|
character |
One character, for example "a", "@", "é"; or a numeric character code, for example 97 for "a". |
modifiers |
Keys held down at the same time: add up the constants WITH_ALT, WITH_CTRL, WITH_COMMAND, WITH_SHIFT (see Key constants). Default 0. |