﻿ KEYSTACK command - Send keystrokes to a program or command
Hide Comments
Purpose:Send keystrokes to a program or command automatically


Format:KEYSTACK [/R filename] [/Wx] ["abc"] [keyname[n]] ...


/WxDelay in clock ticks before next insertion into the keystack.
"abc"Literal characters to be placed in the Keystack.
keynameName of a key whose code is to be placed in the Keystack or its ASCII.
nNumber of times to repeat the immediately preceding named key.


/R(ead file)        /W(ait)






KEYSTACK takes a series of keystrokes and feeds them to a program or command as if they were typed at the keyboard. When the program has used all of the keystrokes in the keystack buffer, it will begin to read the keyboard for input, as it normally would.


KEYSTACK will send the keystrokes to the currently active window. If you want to send keystrokes to another program (rather than have them function with TCC itself), you must start the program or ACTIVATE its window so it can receive the keystrokes. You must do this before executing the KEYSTACK command.


KEYSTACK is most often used for programs started from batch files. In order for KEYSTACK to work in a batch file, you must start the program with the START command, then use the KEYSTACK command. If you start the program directly (without using START) the batch file will wait for the application to complete before continuing and running the KEYSTACK command, and the keystrokes will not appear in the target program.


If you use KEYSTACK in an alias executed from the prompt, the considerations are essentially the same, but depend on whether or not the Wait for External Apps configuration option is set. If it is not set (the default), you can use KEYSTACK immediately after an application is started. However, if Wait for External Apps is set, TCC will not execute any other operation until the program has finished, including the KEYSTACK command, and instead of the target program, the keystrokes will be sent to whatever program is running in the active window when KEYSTACK is executed.


You may not be able to use KEYSTACK effectively if you have programs running in the background which change the active window (for example, by popping up a dialog box). If a window pops up in the midst of your KEYSTACK sequence, keystrokes stored in the KEYSTACK buffer may go to that window, and not to the application you intended.


Keystroke Interpretation


Characters entered within double quotes (for example, "abc") will be sent to the target program as is. The only items allowed outside the quotes are key names, the /W option, and a repeat count. If you want to enter a double quote, use two double quotes. Do not prefix or append the two double quotes to a string argument.) For example, to insert the string abc "def"


keystack "abc " "" "def" ""


If keyname is a single letter, it is inserted in the keystack buffer as if it had been quoted, without any spaces. For example, you could enter the string abc as a b c, instead of the quoted string method described above.


If keyname is a number, it is interpreted as a virtual key code (0 - 255).


Repetition. To send keyname several times, follow it with a space, left bracket [, the repetition count, and a right bracket ]. For example, the command below will send the Enter key 4 times:


keystack enter [4]


The repeat count works only with an individual keyname. It cannot be used with quoted strings. You must have a blank space between the keyname and the repetition count.


See Keys and key names for a complete listing of key names and a description of the key name and numeric key code format.




You may need to experiment with your programs and insert delays (see the /W option) to find the window activation and keystroke sequence that works for a particular program.




To start Word and open the last document you worked on, you could use the command:


start word & keystack /w54 alt-f "1"


This starts Word, delays about three seconds (54 clock ticks at 1/18 second each) for Word to get started, places the keystrokes for Alt-F (File menu),  and 1 (open the most recently used file) into the buffer. Word receives these keystrokes and performs the appropriate actions. Notice that the two commands, START and KEYSTACK are issued on a single command line. This ensures that the keystrokes are sent to Word's window, not back to TCC.




/RRead the KEYSTACK input from a file. (You can only read a single line.)


/WDelay the next keystroke in the KEYSTACK buffer by a specified number of clock ticks. A clock tick is approximately 1/18 second. The number of clock ticks to delay should be placed immediately after the W, and must be between 1 and 65535 (65,535 ticks is about 1 hour). Do not use the Thousands Separator in the number! You can use the /W option as many times as desired and at any point in the string of keystrokes except within double quotes. Some programs may need the delays provided by /W in order to receive keystrokes properly from KEYSTACK. The only way to determine what delay is needed is to experiment.
