[Toc][Index]

KEYSTACK - Feed keystrokes to a program or command

 
 Purpose:    Feed keystrokes to a program or command automatically. 
             
 Format:     KEYSTACK [!] [/Wn] ["abc "] [keyname [n]] ... 
             
             ! :  Signal to clear the Keystack and the keyboard buffer. 
             abc :  Literal characters to be placed in the Keystack. 
             keyname :  Name or code for a key to be placed in the 
             Keystack. 
             n :  Number of times to repeat the named key. 
             
             /W(ait)                         
 
 See also:  Using the Keystack. 
 Usage 
 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 sends the keystrokes to the current active window.  If you want 
 to send keystrokes to another program (rather than have them function 
 with CMD.EXE itself), you must start the program or ACTIVATE its window 
 so it can receive the keystrokes.  The KEYSTACK command must be executed 
 after you start or ACTIVATE the program which is to receive the 
 keystrokes. 
 KEYSTACK is most often used for programs started from batch files.  In 
 order for CMD.EXE's 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 be placed in the buffer too 
 late. 
 If you use KEYSTACK in an alias executed from the prompt, the 
 considerations are essentially the same, but depend on whether ExecWait 
 is set.  If ExecWait is not set, you can use KEYSTACK immediately after 
 an application is started.  However, if ExecWait is set, the KEYSTACK 
 command will not be executed until the program has finished, and the 
 keystrokes will be placed in the buffer too late. 
 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. 
 KEYSTACK will only work if the program KEYSTACK.EXE is in the same 
 directory CMD.EXE.EXE, or a directory listed in your PATH.  If 
 KEYSTACK.EXE cannot be found, the KEYSTACK command will display an error 
 message.  KEYSTACK can send keystrokes to Presentation Manager 
 applications and to OS/2 character-mode applications running in a window. 
  It cannot send keystrokes to DOS applications, or to character-mode 
 applications running in a full-screen session. 
 Characters entered within double quotes ("abc") will be sent "as is" to 
 the application.  The only items allowed outside double quotes are key 
 names, the ! and /W options, and a repeat 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.  If you want to 
 send the same key name or numeric code several times, you can follow it 
 with a repeat count in square brackets.  For example, to send the Enter 
 key 4 times, you can use this command: 

 
         keystack enter [4]
 
 
 The repeat count works only with individual keystrokes, or numeric 
 keystroke or character values.  It cannot be used with quoted strings. 
 An exclamation mark [!] will clear all pending keystrokes in the KEYSTACK 
 buffer. 
 For example, to start a program that needs a single space to skip its 
 opening screen you could use the command: 

 
         [c:\comm] keystack 32 & progname
 
 
 This places a space (ASCII code 32) in the buffer, then runs the program. 
  When the program looks for a keystroke to end the display of the opening 
 screen the keystroke is already in the buffer, and the opening screen is 
 removed immediately. 
 You can store a maximum of 1023 characters in the CMD.EXE KEYSTACK 
 buffer.  The count is determined by the number of characters on the 
 KEYSTACK command line, not by the actual number of characters sent to the 
 application. 
 Each time the KEYSTACK command is executed, it will clear any remaining 
 keystrokes stored by a previous KEYSTACK command. 
 You may need to experiment with your programs and insert delays (see the 
 /W option) to find a keystroke sequence that works for a particular 
 program. 
 Advanced Options 
 KEYSTACK treats the number 0 as a special case; it is used with programs 
 that flush the keyboard buffer.  When KEYSTACK processes a key value of 
 0, it tells the program the buffer is clear, so subsequent keystrokes 
 will be accepted normally.  Some programs will require several "0"s 
 before they will accept input; you may need to experiment to determine 
 the correct number. 
 For example, the following batch file starts a spreadsheet programand 
 loads the file specified on the command line when the batch file is 
 invoked (the KEYSTACK command should be entered on one line): 

 
         pushd c:\finance
         keystack 0 Enter 0 Enter 0 Enter 0 Enter 0
           Enter "/FR" 0 "%1" Enter
         spread
         popd
 
 
 The sequence of "0 Enter" pairs tells the program that the keyboard 
 buffer is empty, then passes a carriage return, repeating this sequence 
 five times.  (You must determine the actual sequence required by your 
 software through experimentation.  Few programs require as long a startup 
 sequence as is shown here.)  This gets the program to a point where an 
 empty spreadsheet is displayed.  The rest of the KEYSTACK line issues a 
 File Retrieve command (/FR), simulates an empty keyboard buffer once 
 more, enters the file name passed on the batch command line (%1), and 
 finally enters a carriage return to end the file name. 
 Here's the same command defined as an alias (enter this on one line): 

 
         alias sload `pushd c:\finance & keystack 0 Enter 0 Enter 0
           Enter 0 Enter 0 Enter "/FR" 0 "%1" Enter & spread & popd`
 
 
 KEYSTACK mimics the BIOS by stacking both an ASCII code and a scan code 
 for each key.  It does so by calculating the code for each character, 
 whether it is entered as part of a quoted string, as a key name, or as an 
 ASCII value less than 128.  However, if you are stacking keys for a 
 program which distinguishes between keys with the same symbol, like the 
 plus on the keyboard and the gray plus, you will have to calculate the 
 codes for the keys on the numeric keypad yourself.  Calculate the value 
 ((256 * scan code) + ASCII code) and enter that numeric value as an 
 argument for KEYSTACK. 
 For example, for the Enter key on the numeric keypad, the scan code is 
 224 and the ASCII code is 13, so to stack both values use ((256 * 224) + 
 13) or KEYSTACK 57357.  Try this approach if a "normal" KEYSTACK command 
 does not work (for example, if you use "KEYSTACK Enter" for the Enter key 
 and the program doesn't see the correct character).  To stack such 
 combined key codes you must use the numeric value, not the key name.  See 
 Reference Tables for ASCII and scan codes. 
 Options 
    /W:     (Wait) Delay 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 (65535 ticks is about 1 hour).  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.  Sometimes a combination of a 
            delay and an "empty buffer" signal (a 0) are required.  For 
            example, to start the program CADX and send it an F7, a delay 
            of one second, an indication that the keyboard buffer is 
            empty, and a carriage return: 

            
                    [c:\] keystack F7 /W18 0 Enter & cadx
            
            
 

Created using Inf-PHP v.2 (c) 2003 Yuri Prokushev
Created using Inf-HTML v.0.9b (c) 1995 Peter Childs