2017-04-02 139 views
0

我的the probably most common form意识到:我们如何使用vbs模拟键盘按键?

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

uncommon and limited way

Set ShellApp = CreateObject("Shell.Application") 
ShellApp.WindowSwitcher 

我们可以hackishlyuse sleep如果我们想键的顺序取决于其他事件:

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

我们不能真的保持按键,但we can repeat it many times

wShell.sendKeys "{LEFT 42}" 

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

+0

你的问题是?你想解决什么问题? –

+0

@AnsgarWiechers我想找出我们使用vbs模拟键盘按键的所有选项,这样我就可以更好地评估我可以用它做什么。 – cregox

+1

在VBScript中,你有'SendKeys'。期。该方法的问题在于它将键击发送到活动窗口,无论在任何给定的时间点。这意味着你无法真正控制击键的实际位置。这就是为什么它应该避免,除非没有其他选择。 –

回答

0

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

同时,我也想通this useful tabled reference可能仍然是有用的如果无耻adapted这里:

大多数ASCII字符可以简单地通过人物本身的表示。例如,键序列FRED可以由“FRED”表示。

特殊键诸如控制键,功能键等进行编码用大括号{}

 
................................................................................................................ 
:  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 %