中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-04 03:17
48,038 topics / 350,123 posts / today 0 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » How to make a BAT press the keyboard keys in order (after 1 second) A, (after 2 seconds) B...
Printable Version  2,414 / 22
Floor1 47cc Posted 2007-04-06 07:41
新手上路 Posts 6 Credits 15
How to make a BAT press the keyboard keys A (after 1 second), B (after 2 seconds), C (after 5 seconds) in sequence
Floor2 lxmxn Posted 2007-04-06 08:09
版主 Posts 4,938 Credits 11,386
Batch script is not suitable, it is recommended to use VBScript.
Floor3 47cc Posted 2007-04-06 08:37
新手上路 Posts 6 Credits 15
If using VBS, how to do it??
Floor4 wudixin96 Posted 2007-04-06 08:48
银牌会员 Posts 931 Credits 1,928
Floor5 bjsh Posted 2007-04-06 08:50
银牌会员 Posts 621 Credits 2,000
Delay used
wscript.sleep 1000 ..............Delay 1 second
Floor6 47cc Posted 2007-04-06 08:55
新手上路 Posts 6 Credits 15
Please provide the Chinese content that needs to be translated.
Floor7 bjsh Posted 2007-04-06 08:59
银牌会员 Posts 621 Credits 2,000
set wshell=WScript.CreateObject("WScript.Shell")
wscript.sleep 1000
wshell.SendKeys "A"
wscript.sleep 1000
wshell.SendKeys "B"
wscript.sleep 3000
wshell.SendKeys "C"
Floor8 wudixin96 Posted 2007-04-06 09:10
银牌会员 Posts 931 Credits 1,928
```set wshshell=WScript.CreateObject("WScript.Shell")
for i=0 to 25
wshshell.SendKeys chr(65+i)
WScript.sleep 1000
next```
Floor9 47cc Posted 2007-04-07 01:32
新手上路 Posts 6 Credits 15
Then how should the keys like "WIN", "ESC", "Enter" in the keyboard be represented?
Floor10 everest79 Posted 2007-04-07 01:40
金牌会员 Posts 1,127 Credits 2,564
win=ctrl+esc, others, he he, you just write it down
Floor11 wudixin96 Posted 2007-04-07 01:42
银牌会员 Posts 931 Credits 1,928
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.
Floor12 47cc Posted 2007-04-07 02:44
新手上路 Posts 6 Credits 15
Sorry! Accidentally clicked the wrong one, turned +1 point into -1~ I'll make it up to you later~~ SORRY ah!
Floor13 9527 Posted 2007-04-07 02:56
银牌会员 Posts 438 Credits 1,185 From 北京
I helped the person upstairs to make up for you.
Floor14 wudixin96 Posted 2007-04-07 03:06
银牌会员 Posts 931 Credits 1,928
Floor15 axi Posted 2007-04-07 12:04
中级用户 Posts 93 Credits 238 From GZ
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 ]
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023