我们如何使用vbs模拟键盘键?

时间:2017-04-02 12:28:23

标签: vbscript

我知道the probably most common form

set wShell = createObject("wscript.shell")
wShell.sendKeys ":){ENTER}"

uncommon and limited way

Set ShellApp = CreateObject("Shell.Application")
ShellApp.WindowSwitcher
如果我们想要一系列依赖于其他事件的键,我们可以 hackishly use sleep

WScript.sleep 987
wShell.sendKeys "foo{!}~"
WScript.sleep 789
wShell.sendKeys "^a^c"

我们无法按下按键,但we can repeat it many times

wShell.sendKeys "{LEFT 42}"

现在......我错过了什么吗?

1 个答案:

答案 0 :(得分:1)

是的,我可能错过了一些东西。

同时我认为this useful tabled reference可能仍然有用如果在这里无耻地adapted

  

大多数ASCII字符只能由字符本身表示。

     

例如,键序列FRED可以用“FRED”表示。

     

控制键,功能键等特殊键用{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                :
:.......................:.......................................:..............................................:
  

要使用SHIFT,CTRL和ALT键的任意组合指定键,请在它们之前进行如下操作:

For SHIFT prefix with +
For CTRL  prefix with ^
For ALT   prefix with %