Method: WshShell.SendKeys

WshShell.SendKeys strKeyString

The SendKeys method sends one or more keystrokes to the active window as if they were typed at the keyboard. This method is similar to VB's SendKeys method.

Each ordinary key can be represented by the character of the key itself. For example, the key sequence ABCD can be represented simply by "ABCD". Some special keys, such as the control keys, function keys, '{', '}', '[', ']', etc... are encoded in a string enclosed by braces ({}).

The following table shows the list of special characters and their respective encoding for SendKeys.


 

Key Code
{ {{}
} {}}
[ {[}
] {]}
~ {~}
+ {+}
^ {^}
% {%}
BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL or Delete {Delete} or {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER {ENTER} or ~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS or Insert {Insert} or {INS}
LEFT ARROW {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
PRINT SCREEN {PRTSC}
RIGHT ARROW {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
UP ARROW {UP}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
F11 {F11}
F12 {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16}

To specify keys combined with any combination of the SHIFT, CTRL, and ALT keys, precede the key code with one or more of the following codes:

Key Code
+ SHIFT
^ CTRL
% ALT

For example, the following strKeyString produces the CTRL-ALT-Delete keystroke combination: "^%{Delete}"

The following VBScript code creates an instance of Notepad and types the words "Hello World!" ten times into Notepad.

Code:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad", 9
WScript.Sleep 500 ' Give Notepad some time to load
For i = 1 To 10
  WshShell.SendKeys "Hello World!"
  WshShell.SendKeys "{ENTER}"
Next




[本日志由 Missll 于 2008-09-24 11:23 AM 编辑]
From: 本站原创 TagsTags:
相关日志:
回复回复Elohim[2008-09-24 10:21 PM | del]
怎么突然弄了个这个。。。记得我当时给改成了fucking the world~~LOL
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.