2017-04-02 153 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 %