Automating user input from keyboard

Automating user input from keyboard

Post by YXplbG1 » Thu, 08 Jul 2004 17:10:01

Hi everyone!

Here is my question:

I want to make a script that runs an application, writes input in it and then closes.

The application is graphical and input must be made with keyboard and/or mouse. Mainly what I am looking for is how to make the script for example to "press" Enter-key or an alphabetical key on the keyboard.

I already have the part where I open the application and close it - it works, but I still have to make the input manually.

If you know where I could find more info on this matter in e.g. the technet that would be helpful as well :)

Thanks for help!


Automating user input from keyboard

Post by MV » Thu, 08 Jul 2004 18:05:39


You have WSH's SendKeys and AppActivate methods, but they are very
limited and has issues.

For a Sendkeys solution that works better, you could use AutoItX


AutoItX.dll is an ActiveX control version of AutoIt and
can be used from e.g. VBScript/Jscript.

An example:

Set oAutoIt = CreateObject("AutoItX.Control")
oAutoIt.SetTitleMatchMode 2

' loop forever
Do While True
' Wait for the window (no timeout)
oAutoIt.WinWait "Some title here", "Maybe some text here", 0
oAutoIt.WinActivate "Some title here", "Maybe some text here"
oAutoIt.Send "{ENTER}"

You will find more examples here: %20send%20AutoItX.Control&safe=images&ie=UTF-8&as_ugroup=*.scripting&as_scoring=d&lr=&hl=en

AutoIt(X) window handling defaults to match the start of a window title that
you specify, use "SetTitleMatchMode 2" to specify ANY substring of the window
title you want to match.

And for the difference on window titles and window text, from the help file:

Window Titles and Window Text

A number of script commands have "Window Title" and "Window Text" as

"Window Title" is text that appears in the windows title bar.

"Window Text" is any other text on that window, e.g. text on buttons such as
"OK" and "Cancel". If you don't wish to specify window text, you must use a
blank string instead, i.e. ""

Having "Window Text" allows you to distinguish between multiple windows that
have the same title.

Neither the title nor text needs to be completely specified.
i.e. "Untitled - No" will match a window with the title "Untitled - Notepad".
See the text on the SetTitleMatchMode command for additions to this.

Hint: Use the "/reveal" mode of the full AutoIt product to see what text is
present on a window.
N.B. Windows titles and text are CASE SENSITIVE!!!!!


torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:


Automating user input from keyboard

Post by YXplbG1 » Thu, 08 Jul 2004 18:33:01


thank you for the quick response :) It will take me some time to go through thi material, but I think I will find a solution to my problem!


"Torgeir Bakken (MVP)" wrote: