中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net  论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
作者:
标题: 如何模拟按键 上一主题 | 下一主题
phywho
初级用户





积分 34
发帖 14
注册 2008-3-12
状态 离线
『楼 主』:  如何模拟按键

我有一个Dos程序,运行后需要逐个输入参数或者回车,有没有办法用批处理解决,谢谢了

2008-3-13 01:04
查看资料  发短消息 网志   编辑帖子  回复  引用回复
DOSforever
金牌会员





积分 4633
发帖 2236
注册 2005-1-30
状态 离线
『第 2 楼』:  

4DOS 的 KSTACK.COM 配合相应的 keystack 命令



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
2008-3-14 01:43
查看资料  发短消息 网志   编辑帖子  回复  引用回复
phywho
初级用户





积分 34
发帖 14
注册 2008-3-12
状态 离线
『第 3 楼』:  



  Quote:
Originally posted by DOSforever at 2008-3-14 01:43 AM:
4DOS 的 KSTACK.COM 配合相应的 keystack 命令

谢谢指点,能不能给出连续输入几个命令的样程呢 :-)

2008-3-14 19:59
查看资料  发短消息 网志   编辑帖子  回复  引用回复
DOSforever
金牌会员





积分 4633
发帖 2236
注册 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
2008-3-15 03:59
查看资料  发短消息 网志   编辑帖子  回复  引用回复
shuiyin313
初级用户





积分 177
发帖 85
注册 2007-12-1
状态 离线
『第 5 楼』:  

金山快译.......

请教~~~只能在4DOS下才能用么?

2008-3-19 04:10
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
DOSforever
金牌会员





积分 4633
发帖 2236
注册 2005-1-30
状态 离线
『第 6 楼』:  



  Quote:
Originally posted by shuiyin313 at 2008-3-19 04:10:
金山快译.......

请教~~~只能在4DOS下才能用么?

金山快译?我不明白和 DOS 有什么关系,金山快译有 DOS 版的?



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
2008-3-19 09:19
查看资料  发短消息 网志   编辑帖子  回复  引用回复
shuiyin313
初级用户





积分 177
发帖 85
注册 2007-12-1
状态 离线
『第 7 楼』:  

读完你的那个HELP文档,只能找我的金山快译了..........
看了好久
英文还没有达到水准~~~~

2008-3-20 04:16
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复

请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: