WshShell.SendKeys

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

      WshShell.SendKeys "Character_string_and/or_SendKeys"

Most ASCII characters can be represented by the character itself.
E.g, the key sequence FRED can be represented by "FRED".
Some special keys, such as the control keys, function keys etc are encoded in a string enclosed by {braces}
See the table below

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
Numlock {NUMLOCK} Send a Num Lock keystroke
Page Down
Page Up
{PGDN}
{PGUP}
Send a Page Down or Page Up keystroke
Print Screen {PRTSC} Send a Print Screen keystroke
Scroll lock {SCROLLLOCK} Press the Scroll lock Key (toggle on or off)
TAB {TAB} Send a TAB keystroke

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

   For SHIFT prefix with +
   For CTRL  prefix with ^
   For ALT   prefix with %

Examples

' Open notepad 
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad.exe", 9

' Give Notepad time to load
WScript.Sleep 500 

' Type in Hello World
WshShell.SendKeys "Hello World!"
WshShell.SendKeys "{ENTER}"

' Add the date
WshShell.SendKeys "{F5}"

“History repeats itself; that's one of the things that's wrong with history” ~ Clarence Darrow

Related:

TechNet - SendKeys Method.
CLIP - Copy STDIN to the Windows clipboard.
Install a Font remotely with VBS - Microsoft Script Center.
Equivalent PowerShell: none but VBScript Sendkeys can be called using New-Object


 
Copyright © 1999-2024 SS64.com
Some rights reserved