The SendKeys method sends keystrokes to the active window. Similar to VB's SendKeys statement.
The SendKeys
method sends one or more keystrokes to the active window as if they
were typed at the keyboard. This method is similar to VB's SendKeys
method.
Each ordinary key can be represented by the
character of the key itself. For example, the key sequence ABCD can be
represented simply by "ABCD". Some special keys, such as the control
keys, function keys, '{', '}', '[', ']', etc... are encoded in a string
enclosed by braces ({}).
The following table shows
the list of special characters and their respective encoding for
SendKeys.
Key | Code |
---|---|
{ | {{} |
} | {}} |
[ | {[} |
] | {]} |
~ | {~} |
+ | {+} |
^ | {^} |
% | {%} |
BACKSPACE | {BACKSPACE}, {BS}, or {BKSP} |
BREAK | {BREAK} |
CAPS LOCK | {CAPSLOCK} |
DEL or DELETE | {DELETE} or {DEL} |
DOWN ARROW | {DOWN} |
END | {END} |
ENTER | {ENTER} or ~ |
ESC | {ESC} |
HELP | {HELP} |
HOME | {HOME} |
INS or INSERT | {INSERT} or {INS} |
LEFT ARROW | {LEFT} |
NUM LOCK | {NUMLOCK} |
PAGE DOWN | {PGDN} |
PAGE UP | {PGUP} |
PRINT SCREEN | {PRTSC} |
RIGHT ARROW | {RIGHT} |
SCROLL LOCK | {SCROLLLOCK} |
TAB | {TAB} |
UP ARROW | {UP} |
F1 | {F1} |
F2 | {F2} |
F3 | {F3} |
F4 | {F4} |
F5 | {F5} |
F6 | {F6} |
F7 | {F7} |
F8 | {F8} |
F9 | {F9} |
F10 | {F10} |
F11 | {F11} |
F12 | {F12} |
F13 | {F13} |
F14 | {F14} |
F15 | {F15} |
F16 | {F16} |
Key | Code |
---|---|
+ | SHIFT |
^ | CTRL |
% | ALT |
Set WshShell =
WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad",
9
WScript.Sleep 500 ' Give Notepad some time to load
For i = 1 To 10
WshShell.SendKeys "Hello
World!"
WshShell.SendKeys "{ENTER}"
Next
This VBScript code creates an instance of Notepad and types the words "Hello World!" ten times into Notepad.