KeyStuff is a Windows 32-bit console utility to load keystroke events into the keyboard queue for processing by subsequent applications. It is useful in BAT (and CMD) files for automating operations of programs that were designed for interactive keyboard use.
License: Use of KeyStuff is free to end users, but I retain the copyright. This program is shared "as-is" without warranty, promise of support, or liability for consequences of its use. Bug reports are requested, and enhancement requests are invited.
Command-line invocation is according to the syntax:
where each token is either a key mnemonic or a literal string.keystuff token1 token2 token3 ...
A key mnemonic is the name of a key optionally preceded by one or more shift qualifiers, separated by hyphens. A shift qualifier is any of Alt-, Ctrl-, Shift-, or Windows-. Valid key names include Enter, F1 through F12, Home, End, Pgup, Pgdn, Left, Right, Up, Down, Ins, Esc, Del, Tab, Bksp, Space, PrtSc, the digits 0 through 9, and the letters A through Z. Case is ignored; the capitalization shown is merely suggested for human readability.
In addition to the names of real keys, KeyStuff defines two pseudo keys, Null and Wait, which support shift qualifiers (or their absence) and time delays.
In some applications, the order in which shift qualifier keys change state is important. With KeyStuff, if two consecutive key mnemonics have any shift qualifiers in common, they are held down while pressing both keys. If two consecutive key mnemonics have different sets of shift qualifiers, only those qualifiers which need to change state are toggled. In this case, the qualifiers associated with only the first one are released (in order Shift, Ctrl, Alt, and Windows) before the qualifiers associated with only the second one are depressed (in the same order). If this is not acceptable, it may be altered with the Null pseudo key.
Null may be used between two keys with the same shift qualifier to specify releasing the shift keys momentarily between them. For example, the command
would act like holding down the Alt key while pressing Tab and then F4, butkeystuff Alt-Tab Alt-F4
would act like momentarily releasing the Alt key in between.keystuff Alt-Tab Null Alt-F4
Conversely, Null may be used to tap a shift qualifier key without pressing any other keys, for example
would briefly tap the Alt key.keystuff Alt-Null
Null may also be used to explicitly specify the order in which shift qualifiers are toggled. For example,
would hold the Shift key while pressing and releasing Tab, then release shift, then hold the Ctrl while pressing and release End, then finally release the Ctrl key. But if overlap between the Shift and Ctrl were necessary, it could be achieved bykeystuff Shift-Tab Ctrl-End
keystuff Shift-Tab Shift-Ctrl-Null Ctrl-End
The pseudo-key Wait is like Null except that it takes an argument, the number of milliseconds to wait. KeyStuff will wait the specified time between "typing" the characters before and after this command. For example,
will cause KeyStuff to "hit" the Alt-Tab combination, release both keys and wait one second, then "hit" the Alt-F4 combination.keystuff Alt-Tab Wait1000 Alt-F4
A fine point: The waiting is done while KeyStuff is still executing, before it puts subsequent keystrokes into the buffer. KeyStuff does not actually stuff any wait codes into the keyboard buffer (in fact, there is no such thing as a wait code).
A literal string is enclosed in a pair of quotation marks (not apostrophes). To include a quotation mark in a literal string, double it up.
It may be instructive to copy each of these commands and paste them onto a command shell command line, then hit Enter to see what they do:
These examples are processed immediately:
|keystuff /?||Display version number and brief help info|
|keystuff Alt-Enter||Toggle shell between full-screen and window|
|keystuff Alt-Tab||Switch to the next window|
|keystuff Alt-Tab Null Alt-F4||Switch to the next window and close it|
|keystuff Windows-D||Minimize all windows to show the Desktop|
|keystuff Windows-Null Wait1000 Esc Alt-Tab||Bring up Start Menu for one second, then close it and return to the previous window|
These examples leave keystrokes to be processed by the command shell interpreter CMD.EXE after KeyStuff exits:
|keystuff "dir" Enter||Execute the shell command "dir"|
|keystuff "echo ""Hello World""" Enter||Type "Hello World" including the quotes|
|keystuff "exit" Enter||Exit the shell|
|keystuff Alt-Space E P||Paste the clipboard into the shell|
Here are some syntactically valid examples that don't work as expected:
|keystuff Ctrl-Alt-Del||Bring up Task Manager|
|1.2||Jan 22, 2004||First release|
|1.3||Jan 27, 2005||Minor bug fixes|
|1.4||Jan 17, 2006||Added pseudo-key Space|
|1.5||Oct 12, 2006||Maximum length of any one literal increased from 256 chars to 16K chars|
|1.6||Nov 8, 2009||Added PrtSc key names.|
Fixed bug due to MapVirtualKey failure to return scan code for period and comma virtual-key codes.