Chinaunix首页 | 论坛 | 博客
  • 博客访问: 85923
  • 博文数量: 33
  • 博客积分: 2500
  • 博客等级: 少校
  • 技术积分: 270
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-15 11:13
文章分类

全部博文(33)

文章存档

2011年(1)

2010年(4)

2008年(28)

我的朋友

分类: WINDOWS

2008-05-06 17:44:45

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
阅读(842) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~