Our Newsletter


Subscribe to our Newsletter and we'll keep you notified of new products, giveaways and discounts.

We respect your email privacy and will never sell or share your details with anyone.


Knowledgebase Home | Glossary | Favorites | Contact | Login Knowledgebase Home | Glossary | Favorites | Contact | Login
Search the Knowledgebase Browse by Category
VBScript SendKeys Function
Article Details

Last Updated
23rd of February, 2009

User Opinions (68 votes)
0% thumbs up 100% thumbs down

How would you rate this answer?
Helpful
Not helpful
Use SendKeys to send keystrokes to another application. This function mimics the behavior of a human sitting at the keyboard, entering keystrokes.

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "calc"
WScript.Sleep 100
WshShell.AppActivate "Calculator"
WScript.Sleep 100

WshShell.SendKeys "5{+}"
WScript.Sleep 500
WshShell.SendKeys "10"
WScript.Sleep 1000
WshShell.SendKeys "="
WScript.Sleep 250



Note: You can send more than 1 key at a time. WshShell.SendKeys "ABC"       ' Sends the keystrokes "ABC"
WshShell.SendKeys "5{+}"      ' Sends the keystrokes "5" and the "+" key



The Following "Special Characters" must be enclosed in "Curly Bracers"
+ {+}
^ {^}
% {%}
~ {~}
{ {{}
} {}}



The Ctrl, Alt and Shift Characters
SHIFT +
CTRL ^
ALT %

To send the SHIFT key followed by the "d" and "e" you would enter +(de) To send a SHIFT-d followed by a Normal e, you would enter +de





Key to Simulate VBScript
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}






     
For more information about VBScript, check out our VBScript Training Videos
VBScript Training Videos
     



Visitor Comments
No visitor comments posted. Post a comment
Post Comment for "VBScript SendKeys Function"
To post a comment for this article, simply complete the form below. Fields marked with an asterisk are required.
   Your Name:
   Email Address:
* Your Comment:
* Enter the code below:
 
Related Articles
No related articles were found.
Attachments
No attachments were found.