Reputation: 18390
I'm aware of the probably most common form:
set wShell = createObject("wscript.shell")
wShell.sendKeys ":){ENTER}"
this uncommon and limited way:
Set ShellApp = CreateObject("Shell.Application")
ShellApp.WindowSwitcher
we can hackishly use sleep if we want a sequence of keys which depends on other events:
WScript.sleep 987
wShell.sendKeys "foo{!}~"
WScript.sleep 789
wShell.sendKeys "^a^c"
and we can't really keep a key pressed but we can repeat it many times:
wShell.sendKeys "{LEFT 42}"
now... am I missing something?
Upvotes: 3
Views: 21191
Reputation: 18390
yeah, I'm probably missing something.
meanwhile I figured this useful tabled reference might still be useful if shamelessly adapted here:
Most ASCII characters can be represented simply by the character itself.
E.g, the key sequence FRED can be represented by "FRED".
Special keys such as the control keys, function keys etc are encoded with {braces}
................................................................................................................ : Key/Character : SendKey : Description : :.......................:.......................................:..............................................: : ~ : {~} : Send a tilde (~) : : ! : {!} : Send an exclamation point (!) : : ^ : {^} : Send a caret (^) : : + : {+} : Send a plus sign (+) : : Backspace : {BACKSPACE} or {BKSP} or {BS} : Send a Backspace keystroke : : Break : {BREAK} : Send a Break keystroke : : Caps Lock : {CAPSLOCK} : Press the Caps Lock Key (toggle on or off) : : Clear : {CLEAR} : Clear the field : : Delete : {DELETE} or {DEL} : Send a Delete keystroke : : Insert : {INSERT} or {INS} : Send an Insert keystroke : : Cursor control arrows : {LEFT} / {RIGHT} / {UP} / {DOWN} : Send a Left/Right/Up/Down Arrow : : End : {END} : Send an End keystroke : : Enter : {ENTER} or ~ : Send an Enter keystroke : : Escape : {ESCAPE} : Send an Esc keystroke : : F1 through F16 : {F1} through {F16} : Send a Function keystroke : : Help : {HELP} : Send a Help keystroke : : Home : {HOME} : Send a Home keystroke : : Page Down : {PGDN} : Send a Page Down keystroke : : Page Up : {PGUP} : Send a Page Up keystroke : : Numlock : {NUMLOCK} : Send a Num Lock keystroke : : Scroll lock : {SCROLLLOCK} : Press the Scroll lock Key (toggle on or off) : : Print Screen : {PRTSC} : Send a Print Screen keystroke : :.......................:.......................................:..............................................:
To specify keys with any combination of SHIFT, CTRL and ALT keys, precede them as following:
For SHIFT prefix with + For CTRL prefix with ^ For ALT prefix with %
Upvotes: 2