China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-04 04:19
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to make a BAT press the keyboard keys in order (after 1 second) A, (after 2 seconds) B... View 2,420 Replies 22
Original Poster Posted 2007-04-06 07:41 ·  中国 贵州 贵阳 移动
新手上路
Credits 15
Posts 6
Joined 2007-03-30 23:49
19-year member
UID 83429
Gender Male
Status Offline
How to make a BAT press the keyboard keys A (after 1 second), B (after 2 seconds), C (after 5 seconds) in sequence
Floor 2 Posted 2007-04-06 08:09 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Batch script is not suitable, it is recommended to use VBScript.
Floor 3 Posted 2007-04-06 08:37 ·  中国 贵州 贵阳 移动
新手上路
Credits 15
Posts 6
Joined 2007-03-30 23:49
19-year member
UID 83429
Gender Male
Status Offline
If using VBS, how to do it??
Floor 4 Posted 2007-04-06 08:48 ·  中国 浙江 杭州 电信
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
set wshell=WScript.CreateObject("WScript.Shell")
wshell.SendKeys "A"
Floor 5 Posted 2007-04-06 08:50 ·  中国 浙江 杭州 华数宽带
银牌会员
★★★
Credits 2,000
Posts 621
Joined 2007-01-01 00:00
19-year member
UID 75212
Gender Male
Status Offline
Delay used
wscript.sleep 1000 ..............Delay 1 second
Floor 6 Posted 2007-04-06 08:55 ·  中国 贵州 贵阳 移动
新手上路
Credits 15
Posts 6
Joined 2007-03-30 23:49
19-year member
UID 83429
Gender Male
Status Offline
Please provide the Chinese content that needs to be translated.
Floor 7 Posted 2007-04-06 08:59 ·  中国 浙江 杭州 华数宽带
银牌会员
★★★
Credits 2,000
Posts 621
Joined 2007-01-01 00:00
19-year member
UID 75212
Gender Male
Status Offline
set wshell=WScript.CreateObject("WScript.Shell")
wscript.sleep 1000
wshell.SendKeys "A"
wscript.sleep 1000
wshell.SendKeys "B"
wscript.sleep 3000
wshell.SendKeys "C"
Floor 8 Posted 2007-04-06 09:10 ·  中国 浙江 杭州 电信
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
```set wshshell=WScript.CreateObject("WScript.Shell")
for i=0 to 25
wshshell.SendKeys chr(65+i)
WScript.sleep 1000
next```
Floor 9 Posted 2007-04-07 01:32 ·  中国 贵州 贵阳 电信
新手上路
Credits 15
Posts 6
Joined 2007-03-30 23:49
19-year member
UID 83429
Gender Male
Status Offline
Then how should the keys like "WIN", "ESC", "Enter" in the keyboard be represented?
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
kongfu1123 +1 2007-04-21 13:17
Floor 10 Posted 2007-04-07 01:40 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
win=ctrl+esc, others, he he, you just write it down
Floor 11 Posted 2007-04-07 01:42 ·  中国 浙江 杭州 电信
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
SendKeys Method
See Also
WshShell Object | Run Method
Sends one or more keystrokes to the active window (as if the keys were pressed on the keyboard).

object.SendKeys(string)
Parameters
object
WshShell object.
string
String value representing the keystroke(s) to send.
Remarks
The SendKeys method can be used to send keystrokes to applications that have no automation interface. Most keyboard characters can be represented by one keystroke. Some keyboard characters are composed of multiple keystrokes (for example, CTRL+SHIFT+HOME). To send a single keyboard character, send the character itself as the string parameter. For example, to send the letter x, send the string parameter "x".

Note To send a space, send the string " ".
You can send multiple keystrokes at the same time using SendKeys. To do this, place each keystroke in sequence to create a composite string parameter representing a series of keystrokes. For example, to send the keystrokes a, b, and c, send the string parameter "abc". The SendKeys method uses certain characters as modifiers for characters (rather than using their literal meaning). This special set of characters can include parentheses, brackets, braces, and:

Plus sign "+",
Caret "^",
Percent sign "%"、
and "Tilde" symbol "~".
Enclose these characters in braces "{}" to send them. For example, to send a plus sign, use the string parameter "{+}". The brackets "[]" used in SendKeys have no special meaning, but must be enclosed in braces to accommodate applications that do assign them special meaning (for example, for Dynamic Data Exchange (DDE)).

To send a left bracket character, send the string parameter "{[]"; to send a right bracket character, send the string parameter "{]}".
To send a left brace character, send the string parameter "{{}"; to send a right brace character, send the string parameter "{}}".
Some keystrokes do not produce characters (such as ENTER and TAB). Some keystrokes represent actions (such as BACKSPACE and BREAK). To send these types of keystrokes, send the parameters listed in the following table:

Key Parameter
Backspace {BACKSPACE}, {BS}, or {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL or DELETE {DELETE} or {DEL}
Down arrow {DOWN}
END {END}
ENTER {ENTER} or ~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS or INSERT {INSERT} or {INS}
Left arrow {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
PRINT SCREEN {PRTSC}
Right arrow {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
Up arrow {UP}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
F11 {F11}
F12 {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16}

To send keyboard characters composed of a regular keystroke and a combination of SHIFT, CTRL, or ALT, create a composite string parameter representing that keystroke combination. You can do this by adding one or more of the following special characters before the regular keystroke:

Key Special Character
SHIFT +
CTRL ^
ALT %

Note Do not enclose these special characters in braces when used this way.
To specify a combination of SHIFT, CTRL, and ALT while pressing several other keys, create a composite string parameter with the combination enclosed in parentheses. For example, to send a combination specified as:

If SHIFT is pressed while pressing e and c, send the string parameter "+(ec)".
If only c is pressed while pressing e (without pressing SHIFT), send the string parameter "+ec".
You can use the SendKeys method to send a keystroke that repeats a key press within a line. To do this, create a composite string parameter specifying the keystroke to repeat, and then specify the number of repetitions after it. You can do this using a composite string parameter in the form {keystroke number}. For example, if you want to send "x" 10 times, you need to send the string parameter "{x 10}". Make sure there is a space between the keystroke and the number.

Note You can only send keystrokes that repeat pressing a single key. For example, you can send "x" 10 times, but you cannot send "Ctrl+x" 10 times.
Note You cannot send the PRINT SCREEN key {PRTSC} to an application.
Recent Ratings for This Post ( 3 in total) Click for details
RaterScoreTime
47cc -1 2007-04-07 01:47
9527 +13 2007-04-07 02:55
vlq5299 +1 2007-04-10 13:08
Floor 12 Posted 2007-04-07 02:44 ·  中国 贵州 贵阳 电信
新手上路
Credits 15
Posts 6
Joined 2007-03-30 23:49
19-year member
UID 83429
Gender Male
Status Offline
Sorry! Accidentally clicked the wrong one, turned +1 point into -1~ I'll make it up to you later~~ SORRY ah!
Floor 13 Posted 2007-04-07 02:56 ·  中国 北京 联通
银牌会员
★★★
努力做坏人
Credits 1,185
Posts 438
Joined 2006-08-28 12:00
19-year member
UID 61449
From 北京
Status Offline
I helped the person upstairs to make up for you.
我今后在论坛的目标就是做个超级坏人!!!
Floor 14 Posted 2007-04-07 03:06 ·  中国 浙江 杭州 电信
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
Floor 15 Posted 2007-04-07 12:04 ·  中国 广东 广州 番禺区 电信
中级用户
★★
脚本爱好者
Credits 238
Posts 93
Joined 2007-03-11 13:38
19-year member
UID 81417
Gender Male
From GZ
Status Offline
Here are more examples:

http://www.cn-dos.net/forum/viewthread.php?tid=28377&fpage

Friends interested in learning VBS can go to:

http://doc.51windows.net/vbscript/?url=/vbscript/html/vtoriVBScript.htm

[ Last edited by axi on 2007-4-6 at 11:18 PM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
lxmxn +10 2007-04-07 12:31
Forum Jump: