Send keystrokes with VBScript

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Send keystrokes with VBScript

Post by Marcus Tettmar » Mon Feb 21, 2005 10:27 pm

An alternative way to send keystrokes can be achieved by using the Windows Scripting Shell object in VBScript:

VBSTART
Sub Send
Dim Wsh
Set Wsh = CreateObject("Wscript.Shell")
Wsh.AppActivate "Notepad"
Wsh.SendKeys "Hello World{ENTER}"
End Sub
VBEND

Run>Notepad
WaitWindowOpen>Notepad*
VBRun>Send

This could be useful where you need to send keystrokes from within a complicated VBScript routine and/or would prefer to keep control within VBScript.

For further details and a list of key codes see:
http://msdn.microsoft.com/library/en-us ... ndkeys.asp

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts