2

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?

Community
  • 1
  • 1
cregox
  • 17,674
  • 15
  • 85
  • 116
  • What is your question? What problem are you trying to solve? – Ansgar Wiechers Apr 02 '17 at 16:14
  • @AnsgarWiechers I want to find out all options we have for simulating keyboard keys using vbs so I can better assess what I can do with it. – cregox Apr 03 '17 at 10:30
  • 2
    In VBScript you have `SendKeys`. Period. The problem with that method is that it sends the keystrokes to the active window, whatever that is at any given point in time. Meaning you cannot really control where your keystrokes actually are going. That's why it should be avoided unless there is no other option. – Ansgar Wiechers Apr 03 '17 at 12:26

1 Answers1

1

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 %
Community
  • 1
  • 1
cregox
  • 17,674
  • 15
  • 85
  • 116