SendKeys
- Last UpdatedJul 18, 2023
- 2 minute read
Sends a keystroke (or string of keystrokes) to a window as if they were typed on the keyboard. The window receives input focus and is brought to the foreground.
This function is a blocking function. It blocks the calling Cicode task until the operation is complete.
Syntax
SendKeys(sTitle, sKeys)
sTitle:
The title (caption) of the destination window.
sKeys:
The key (or keys) to send to sTitle.
• To send a single keyboard character, use the character itself. For example, to send the letter a, set sKeys to a. To send more than one character, append each additional character to the string. For example, to send the letters a, b, and c, set sKeys to abc.
• The plus (+), caret (^), and percent sign (%) have special meanings. To send one of these special characters, enclose the character with braces. For example, to send the plus sign, use {+}. To send a { character or a } character, use {{} and {}}, respectively.
• To specify characters that are not displayed when you press a key (such as Enter or Tab) and other keys that represent actions rather than characters, use the codes shown below:
|
Key |
Code |
|
Backspace |
{backspace} or {bs} or{bksp} |
|
Break |
{break} |
|
Caps Lock |
{capslock} |
|
Clear |
{clear} |
|
Del |
{delete} or {del} |
|
End |
{end} |
|
Enter |
{enter} or ~ |
|
Esc |
{escape} or {esc} |
|
Help |
{help} |
|
Home |
{home} |
|
Insert |
{insert} |
|
Num Lock |
{numlock} |
|
Page Down |
{pgdn} |
|
Page Up |
{pgup} |
|
Print Screen |
{prtsc} |
|
Scroll Lock |
{scrolllock} |
|
Tab |
{tab} |
|
Up Arrow |
{up} |
|
Down Arrow |
{down} |
|
Right Arrow |
{right} |
|
Left Arrow |
{left} |
|
F1 |
{f1} |
|
F2 |
{f2} |
|
F3 |
{f3} |
|
F4 |
{f4} |
|
F5 |
{f5} |
|
F6 |
{f6} |
|
F7 |
{f7} |
|
F8 |
{f8} |
|
F9 |
{f9} |
|
F10 |
{f10} |
|
F11 |
{f11} |
|
F12 |
{f12} |
To specify keys combined with any combination of Shift, Ctrl, and Alt, precede the regular key code with one or more of these codes:
|
Key |
Code |
|
Shift |
+ |
|
Ctrl |
^ |
|
Alt |
% |
To specify that Shift, Ctrl, and/or Alt are held down while several keys are pressed, enclose the keys in parentheses. For example, to hold down the Shift key while sending E then C, use +(EC). To hold down Shift while sending E, followed by C without the Shift key, use +EC. To specify repeating keys, use the form {key number}. For example, {left 42} means send the left arrow key 42 times. Be aware that you need to leave a space between the key and number.
Return Value
0 (zero) if successful, otherwise an error code is returned.
Related Functions
Example
SendKeys("Untitled - Notepad", "abc");
// Send the key sequence "abc" to the Notepad application