DOSforever
金牌会员
积分 4639
发帖 2239
注册 2005-1-30
状态 离线
|
『第
4 楼』:
你耐心看完就明白了
Quote: | 4DOS Help Topic: KEYSTACK
Purpose: Feed keystrokes to a program or command automatically.
Format: KEYSTACK [!] [/Wx] ["abc"] [keyname[n]] ...
!: Signal to clear the Keystack and the keyboard buffer.
x: Delay in clock ticks.
"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)
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 places keystrokes into a buffer. When an application program (or
4DOS itself) requests another keystroke, the "stacked" keystroke is
retrieved from the buffer. The KEYSTACK command must be executed before
running the program which is going to receive the keystrokes in order to put
the keystrokes into the buffer first, so the program can find them when it
runs.
KEYSTACK will only work if the memory-resident program KSTACK.COM has been
loaded. KSTACK is usually loaded from AUTOEXEC.BAT. If KSTACK is not
loaded, the KEYSTACK command will display an error message. To load
KSTACK.COM, add this line to AUTOEXEC.BAT:
d:\path\KSTACK.COM
where d:\path is the directory where your 4DOS files are stored. If you are
using Windows 95/98/ME, see Installing KSTACK in Windows 95/98/ME.
Programs that bypass DOS and the BIOS for keyboard input cannot read
keystrokes entered with KEYSTACK. If you use KEYSTACK and then run such a
program, the keystrokes will not appear in the program, but may appear at
the prompt when you exit the program and return to 4DOS.
Characters entered within double quotes ("abc") will be sent "as is" to the
application. The only items allowed outside double quotes are key names,
key codes, 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, both in the
KEYSTACK buffer and in the BIOS keyboard 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 511 text or special characters in the KEYSTACK
buffer. A delay takes two character slots in the buffer. 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 program and loads
the file specified on the command line when the batch file is invoked:
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 ASCII and Key Codes for a complete list of ASCII codes and scan
codes.
Option
/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 |
|
|
DOS倒下了,但永远不死
DOS NEVER DIES !
投票调查:
http://www.cn-dos.net/forum/viewthread.php?tid=46187
本人尚未解决的疑难问题:
http://www.cn-dos.net/forum/viewthread.php?tid=15135
http://www.cn-dos.net/forum/viewthread.php?tid=47663
http://www.cn-dos.net/forum/viewthread.php?tid=48747 |
|