SendKeys Method
See Also
WshShell Object | Run Method
Sends one or more keystrokes to the active window (as if the keys were pressed on the keyboard).
object.SendKeys(string)
Parameters
object
WshShell object.
string
String value representing the keystroke(s) to send.
Remarks
The SendKeys method can be used to send keystrokes to applications that have no automation interface. Most keyboard characters can be represented by one keystroke. Some keyboard characters are composed of multiple keystrokes (for example, CTRL+SHIFT+HOME). To send a single keyboard character, send the character itself as the string parameter. For example, to send the letter x, send the string parameter "x".
Note To send a space, send the string " ".
You can send multiple keystrokes at the same time using SendKeys. To do this, place each keystroke in sequence to create a composite string parameter representing a series of keystrokes. For example, to send the keystrokes a, b, and c, send the string parameter "abc". The SendKeys method uses certain characters as modifiers for characters (rather than using their literal meaning). This special set of characters can include parentheses, brackets, braces, and:
Plus sign "+",
Caret "^",
Percent sign "%"、
and "Tilde" symbol "~".
Enclose these characters in braces "{}" to send them. For example, to send a plus sign, use the string parameter "{+}". The brackets "[]" used in SendKeys have no special meaning, but must be enclosed in braces to accommodate applications that do assign them special meaning (for example, for Dynamic Data Exchange (DDE)).
To send a left bracket character, send the string parameter "{[]"; to send a right bracket character, send the string parameter "{]}".
To send a left brace character, send the string parameter "{{}"; to send a right brace character, send the string parameter "{}}".
Some keystrokes do not produce characters (such as ENTER and TAB). Some keystrokes represent actions (such as BACKSPACE and BREAK). To send these types of keystrokes, send the parameters listed in the following table:
Key Parameter
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 send keyboard characters composed of a regular keystroke and a combination of SHIFT, CTRL, or ALT, create a composite string parameter representing that keystroke combination. You can do this by adding one or more of the following special characters before the regular keystroke:
Key Special Character
SHIFT +
CTRL ^
ALT %
Note Do not enclose these special characters in braces when used this way.
To specify a combination of SHIFT, CTRL, and ALT while pressing several other keys, create a composite string parameter with the combination enclosed in parentheses. For example, to send a combination specified as:
If SHIFT is pressed while pressing e and c, send the string parameter "+(ec)".
If only c is pressed while pressing e (without pressing SHIFT), send the string parameter "+ec".
You can use the SendKeys method to send a keystroke that repeats a key press within a line. To do this, create a composite string parameter specifying the keystroke to repeat, and then specify the number of repetitions after it. You can do this using a composite string parameter in the form {keystroke number}. For example, if you want to send "x" 10 times, you need to send the string parameter "{x 10}". Make sure there is a space between the keystroke and the number.
Note You can only send keystrokes that repeat pressing a single key. For example, you can send "x" 10 times, but you cannot send "Ctrl+x" 10 times.
Note You cannot send the PRINT SCREEN key {PRTSC} to an application.
Recent Ratings for This Post
( 3 in total)
Click for details
| Rater | Score | Time |
| 47cc |
-1 |
2007-04-07 01:47 |
| 9527 |
+13 |
2007-04-07 02:55 |
| vlq5299 |
+1 |
2007-04-10 13:08 |