Press keys harder with science

Let’s assume you have some tedious, repetitive task that needs doing that’s essentially a series of keyboard keystrokes with no brainpower needed — inputting a series of numbers, pressing the same menu items in a row, mining for fish in the clunky F2P MMO du jour. Maybe this tedious task is something you need to do on your library management software. Who knows?

Here’s some VBA script that simulates key presses and sends them to the selected application:

' create a windows shell object
Set wshShell = CreateObject("WScript.Shell")

' match this string to the window title
wshShell.AppActivate("My Application Title")

' give the application a keypress and wait
wshShell.SendKeys(sKeystrokes)
WScript.Sleep 500

For the next step, imagine putting the SendKeys and Sleep commands in a loop, taking input from a file, perhaps, while you turn off the monitor and settle into a hammock with a mixed drink.

The Sleep command is useful when sprinkled in liberally. Sometimes you need to allow a little time for the UI to react to whatever keys have been pressed; especially if the application you’re sending them to is a clunky piece of Java. For example.

Leave a Reply

Your email address will not be published. Required fields are marked *