2023年12月2日发(作者:)

vbs实现自动按键(VBS Auto Key)

The script implements a key that is automatically pressed by

the keyboard:

Press F5

Interval 50 milliseconds

Loosen F5

Interval 3000 milliseconds

Press F5

Interval 50 milliseconds

Loosen F5

Back to the first step

Batch processing doesn't work. Using VBS is a simple example

Set objShell = CreateObject ("")

Do

3000

ys "{F5}""

3000 ys "{F5}""

Loop

Use the SendKeys method to send keystrokes to the application

of automation interface. Most keyboard characters are

available a keystroke said. Some characters on the keyboard is

composed of a plurality of keystrokes assembled (e.g.,

CTRL+SHIFT+HOME). To send a single keyboard character, send the

character itself as the string parameter. For example, if you

want to send the letter X, send the string parameter "x"".

SendKeys can be used to simultaneously transmit multiple

keystrokes. To this end, can be arranged together each

keystroke in order to create a series of string parameters

representing the complex keystrokes. For example, to send

keystrokes to a, B and C, you need to send a string parameter

"abc". The SendKeys method uses some characters as modifiers

of characters without using their own meanings. This special

set of characters can include parentheses, brackets, braces,

and so on:

Plus "+""

Insert mark "^""

Sign "%"

And "non" symbol "~""

With a brace "{}" these characters can send them. For example,

to send a plus, please use the string parameter "{+}". The use

of SendKeys in the brackets "[]" without any special meaning,

but they must be enclosed in braces, to accommodate the

application is to give it a special meaning (for example, for

the dynamic data exchange (DDE) is such).

To send the left bracket characters, please send a string

parameter "{[}"; to send the right bracket characters, please

send a string parameter "{]}".

To send a left brace character, please send a string parameter

"{{}"; to send altmode characters, please send a string

parameter "{}}".

Some keystrokes do not generate characters (such as ENTER and

TAB). Some keystrokes said operation (such as BACKSPACE and

BREAK). To send these types of keystrokes, please send the

parameters listed in the table below:

Space key""

Backspace key {BACKSPACE} or {BS} or {BKSP}

BREAK {BREAK}

DELETE {DELETE} or {DEL}

Down key {DOWN}

Up arrow {UP} Left key {LEFT}

Right key {RIGHT}

END {END}

ENTER {ENTER} or ~!

ESC {ESC}

TAB {TAB}

CAPS LOCK {CAPSLOCK}

HELP {HELP}

HOME {HOME}

INSERT {INSERT} or {INS}

NUM LOCK {NUMLOCK}

PAGE DOWN {PGDN}

PAGE UP {PGUP}

PRINT SCREEN {PRTSC}

SCROLL LOCK {SCROLLLOCK}

F1 {F1}

F2 {F2}

f3 f3} {

{} f4 f4

f5, f5 {}.

f6 f6} {

f7 f7} {

f8 {d8}

f9} {f9

f10 f10} {

f11 f11} {

f12 f12} {

要发送由常规键击和 shift、ctrl 或 alt 组合而成的键盘字符, 请创建表示该键击组合的复合字符串参数.可通过在常规键击之前添加一个或多个以下特殊字符来完成上述操作:

shift +

ctrl ^ alt%

注意: 这样使用时, 不用大括号括起这些特殊字符.

要指定在按下多个其他键时, 按下 shift、ctrl 和 alt 的组合, 请创建复合字符串参数, 用括号括起其中的组合键.例如, 要发送的组合键指定:

this 和 如果在按 c 的同时按 shift 键, 则发送字符串参数 "+

(ec)".

this 时只按 如果在按 c (而不按 shift), 则发送字符串参数 "+

ec".

可使用 sendkeys 方法发送一种在一行内重复按键的键击.为此, 要创建复合字符串参数, 以指定要重复的键击, 并在其后指定重复次数.可使用 数字} {键击 形式的复合字符串参数来完成上述操作.例如, 如果要发送 次 10 "x", "x 则需要发送字符串参数 {10}".请确保在键击和数字之间有一个空格.

注意: 只可以发送重复按一个键的键击.例如, 可以发送 10 "x 10",

次 但不可发送 次 "ctrl + x".

注意: 不能向应用程序发送 print screen prtsc 键 {}.

例子1: 关机脚本 (模拟按键为: ctrl + esc、u、u)

把以下代码复制至记事本, 另存为

set wshshell = createobject ("") ys "^ {esc} ("

例子2: 重启脚本 (模拟按键为: ctrl + esc、u、r)

把以下代码复制至记事本, 另存为

set wshshell = createobject ("")

ys "^ {esc}."

例子3: 切换输入法 (模拟同时按下 shift ctrl)

set wshshell = createobject ("")

ys "+ (^)"

例子4: 输入 . 至记事本并保存为

dim wshshell

set wshshell = object ("")

wshshell run "notepad".

wscript sleep 1500.

ivate "无标题 - 记事本"

ys "c"

wscript. 200.

ys "n"

wscript. 200.

ys "-"

wscript. 200.

ys "d"

wscript. 200.

ys "o"

wscript. 200.

ys "s"

wscript. 200.

ys "."

wscript. 200.

ys "n"

wscript. 200.

ys "e" wscript. 200.

ys "t"

wscript. 200.

wshshell.

SendKeys”!”

睡200名。

ys“% FS”

睡500名。

ys“C”

睡200名。

ys“N”

睡200名。

ys“D”

睡200名。

ys“O”

睡200名。

ys“S”

睡200名。

ys“%s”

睡500名。

ys %“FX”

例子5:自动定时存盘的记事本(此脚本来自网上)

“第一部分:定义变量和对象

昏暗的wshshell,autosavetime,TXTFileName

autosavetime =(1000×60×1)的1分钟自动存盘时间为

集wshshell =名。CreateObject(“wscript。壳”)

txtfilename = InputBox(“给文本起名(不能用中文和纯数字):”)

“第二部分:打开并激活记事本

这是通过WSHShell.运行“记事本”

睡200名。

ivate”无标题-记事本” “第三部分:用输入的文件名存盘

ys”^”

睡300名。

ys txtfilename

睡300名。

ys“%s”

睡眠autosavetime名。

“第四部分:自动定时存盘

而ivate(txtfilename)=真

ys”^”

睡眠autosavetime名。

WScript。退出

例子:

集objshell = CreateObject(“wscript。壳”)

strcommandline =“psetup755281 .exe”启动安装程序

objshell运行(strcommandline)。

集wshshell = CreateObject(“wscript。壳”)

名。睡眠2000延时3秒

ys“{Enter}”模拟按下回车键执行下一步

名。睡眠300延时3秒

ys“{Enter}”模拟按下回车键执行下一步

名。睡眠300延时3秒

ys“{Enter}”模拟按下回车键执行下一步

名。睡眠5200延时3秒

ys“{Enter}”模拟按下回车键执行下一步

名。睡眠300延时3秒

ys“{Enter}”模拟按下回车键执行下一步

名。睡眠300延时3秒

ys“{Enter}”模拟按下回车键执行下一步

睡200名。 “ys”模拟按下空格键去除安装百度超级搜霸一行前的√号

睡100名。

ys“{Tab}”模拟按下选项卡键选择安装项目

睡200名。

“ys”模拟按下空格键去除安装百度超级搜霸一行前的√号

名。睡眠200延时0.3秒

ys“F”模拟按下F键同意协议

*************

另外方式:

< %

昏暗的末日

结果= timer()

”页面执行时间:“formatnumber(结束时间*

1000,3)和“毫秒”

%> 对比下面是计算相差的日期

< %

姓名=“2008-1-10”

diffadate = DateDiff(“D”,姓名,现在)

%>

***************************************************************

VBS中SendKeys方法将响应键盘的操作,并发送此值。这样将实现许多有趣、适用、方便的功能!基本上只要键盘能完成的操作,SendKeys就能一并完成。你想到了什么?嘿嘿!下面的代码是经过我一个晚上的整理与测试。其中QQ自动登录的不成功!不是代码不行,估计是最新版QQ的保护机制!

第一个例子、将下面这段代码保存为,运行此VBS,将会打开我的博客。

集合S =名。CreateObject(“wscript。壳”)的创建壳对象名。

应用=主持(“iexplore”)的打开IE浏览器

名。睡眠1000这表示停顿1000毫秒,即1秒,下面一样......

ivate APP

ys”+ {Tab}”

ys”/ycosxhack”

ys“{Enter}”

这段代码响应了键盘三个动作:Shift + Tab聚焦于地址栏、键入”HTTP:/ /嗨。百度。COM / ycosxhack”、进入回车于是这样就打开我的博客了^ ^。

第二个例子、将下面代码保存为QQ。vbs,运行此VBS,将会自动输入你的QQ帐号与密码,然后登录。

集合S =名。CreateObject(“wscript。壳”)

应用=主持(“D:程序~ 1 腾讯 QQ、QQ .exe”)的你QQ的路径!

“注意程序文件要写成程序~ 1,我一个晚上测试出来的答案——!!

睡1000名。

ivate APP

ys”+ {Tab}”

睡500名。

ys“78669255”

ys“{Tab}”

睡500名。

ys“123456”

睡1000名。

ys“{Enter}”

这段代码响应了键盘五个动作:Shift + Tab键、输入QQ号78669255、选项卡、输入QQ密码123456、进入回车,测试时,将这些值换成你自己的。

能懂这两个例子,其它不就可以举一反三了吗?记住只要键盘能完成的SendKeys基本都是可以完成的!那些黑客们经常用到的快捷键(基本不用鼠标就可以完成任务!)都可以模拟出来,再举个小例子,打开”任务管理器”,按Ctrl + Shift + Esc对吧?看下面代码:

集合S =名。CreateObject(“wscript。壳”)

ys”^ + { ESC }”

运行后,是不是打开任务管理器啦?要关闭电脑?调用CMD?删除文件?格式硬盘?等等,通过SendKeys方法皆可轻易完成!这在某些方面也许会很有用,比如:黑客方面......

呃~ ~ ~上面的SendKeys方法是不是有点地方不明白?如:打开”任务管理器”的例子,SendKeys”^ + { ESC }”中^ + ESC } {为什么代表Ctrl+Shift+Esc?放心,最后我会给出MSDN的SendKeys方法的帮助文档,很简单,自己一看就会恍然大悟的^ ^!

最后来个有点恶作剧的例子,就是网上有点流行的“QQ消息疯狂乱发”,如何实现?看下面代码:

集wshshell =名。CreateObject(“wscript。壳”)

ivate”

我= 1到100循环发送消息100次!

睡2000名。

ys”^ V”粘贴剪切板里的内容到QQ聊天面板上!

ys“%s”发送......

下一个

打开某位好友或某个群的聊天面板,

wscript: 1000.

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

= = = = = = = = = = = = = = = = =

- i 如何模拟回车, 上档键, alt键喃?

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

= = = = = = = = = = = = = = = = =

- i 如何模拟回车 {enter} 这就代表是发送回车...

this is a ys enter. {enter} " wscript: 1000.

- - - + 这就代表是发送shift 如何模拟上档键shift.

this is ys "," this is a 结果为

wscript: 1000.

- i 如何模拟alt 这就代表是发送alt -%

this is ys% {tab} "结果为 切换窗口

wscript: 1000.

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

= = = = = = = = = = = = = = = = = = = = = = = = = = = =

- i 喃 那么如何发送% +.

this is ys {+} {^ {%) "结果为 切换窗口

wscript: 1000.

- i 这里你可能已经明白了, 发送送特殊字符时, 请放到 {} 中

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

= = = = = = = = = = = = = = = = = = = = = = = = = = = =

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

= = = = = = = "更多信息请看vbs帮助文档 2009 / 07 / 26

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

= = = = = = =