1.1. ESSO SendKeys syntax
SendKeys syntax
The sendKeys function aims to perform as the user pressing keystrokes. Thus, the function SendKeys ("ABC") simulates to press those three letters.
The keystrokes will be done independently of the application that generates them. Thus, it is possible to press keys that change the focused control or even the active application using sendKeys.
To mimic the action of pressing to keys simultaneously, you can make use of modifiers. The available modifiers are listed at the attached table. So, to send the character ':' you can execute execute sendKeys("+."). This combination will simulate pressing the Shift key along with '.'. In order to allow a simpler syntax, you can use parentheses to specify more than one key affected by modifiers. Thus, the function function SendKeys ("+ (hello)") generates the word HELLO in upper case.
Modifier |
Key |
@ |
WINDOWS |
+ |
SHIFT |
^ |
CTRL |
% |
ALT |
It should be noted that this method can not get accented letters as a parameter, but the combination necessary to generate the desired letter. This method has a big drawback. The combination of keys needed to get a letter can be different depending of the current keyboard layout. So, in order to send arbitrary text characters, it is recommended to use the function function sendText.
Additionally, the sendKeys function supports this “virtual keystrokes” that do not correspond to a specific key but an actual action do be done:
Tag |
Action taken. |
VKEY {X} |
The virtual code key (VKEY) will be sent. |
XY {BEEP} |
A sound with a frequency X during Y time (in milliseconds). |
{DELAY X} |
X milliseconds pause. |
{DELAY = X} |
Make a dealy of X milliseconds between each simulated keystrokes. |
{AppActivate WindowTitle} |
Bring foreground and activates the application with the specified title. |
To send function keys, you can use the following codes:
Key |
Tag |
Key |
Tag |
Backspace |
{BACKSPACE} or {BS} |
F1 |
{F1} |
Break |
{BREAK} |
F2 |
{F2} |
CapsLock |
{CAPSLOC} |
F3 |
{F3} |
Delete |
{DELETE} or {DEL} |
F4 |
{F4} |
Down arrow |
{DOWN} |
F5 |
{F5} |
End |
{END} |
F6 |
{F6} |
Enter |
{ENTER} or ~ |
F7 |
{F7} |
Ex |
{ESC} |
F8 |
{F8} |
Help |
{HELP} |
F9 |
{F9} |
Home |
{HOME} |
F10 |
{F10} |
Lnsert |
{INS} |
F11 |
{F11} |
Left arrow |
{LEFT} |
F12 |
{F12} |
Num Lock |
{NUMLOCK} |
F13 |
{F13} |
Next page |
{PGDN} |
F14 |
{F14} |
Previous page |
{PGUP} |
F15 |
{F15} |
Print screen |
{PRTSC} |
F16 |
{F16} |
Right Arrow |
{RIGHT} |
^ |
{CARET} |
Scroll Lock |
{SCROLL} |
~ |
{Tilde} |
Tab |
{TAB} |
{ |
{LEFTBRACE} |
Up arrow |
{UP} |
} |
{RIGHTBRACE} |
+ (Numeric keypad) |
{ADD} |
( |
{LEFTPAREN} |
- (Numeric keypad) |
{SUBSTRCT} |
) |
{RIGHTPAREN} |
* (Numeric keypad) |
{Multiply} |
windows (left) |
{LWIN} or {RWIN} |
/ (Numeric keypad) |
{DIVIDE} |
windows (right) |
{RWIN} |
+ |
{PLUS} |
context menu |
{APPS} |
@ |
{AT} |
|
|
Here are a few small examples :
sendKeys parameter |
Effect |
{DELAY=50} |
1. |
@R |
2. |
notepad~ |
3. |
hello world! |
4. |
%ua |
5. |
{Delay = 100} |
1. |
{AppActivate Calculator} |
2. |
{ESC} |
3. |
5*7~ |
4. |
{beep 1000 500} |
5. |
^C |
6. |
{appactivate Notepad} |
7. |
^E |
8. |
{DEL} |
9. |
Result of 5 * 7 is: |
10. |
^V |
11. |
{DELAY=500}{NUMLOCK}{CAPSLOCK}{SCROLL} |
1.
|
{SCROLL}{CAPSLOCK}{NUMLOCK} |
2. |
{DELAY=500} |
1. |
%? |
2. |
{DOWN 5} |
3. |