快速业务通道

VBS中SendKeys的基本应用

作者 佚名 来源 ASP编程 浏览 发布时间 2013-07-09
ps:不知道有人还记得这个攻击qq群的代码?就是利用这个所写的!
SendKeys
模拟键盘操作,将一个或多个按键指令发送到指定Windows窗口来控制应用程序运行,
其使用格式为:object.SendKeysstring

“object”:表示WshShell对象
“string”:表示要发送的按键指令字符串,需要放在英文双引号中。

1.基本键

  一般来说,要发送的按键指令都可以直接用该按键字符本身来表示,例如要发送字母“x”,使用“WshShell.SendKeys"x"”即可。当然,也可直接发送多个按键指令,只需要将按键字符按顺序排列在一起即可,例如,要发送按键“happy”,可以使用“WshShell.SendKeys"happy"”。

2.特殊功能键

  对于需要与Shift、Ctrl、Alt三个控制键组合的按键,SendKeys使用特殊字符来表示:

Shift---------WshShell.SendKeys"+"
Ctrl---------WshShell.SendKeys"^"
Alt---------WshShell.SendKeys"%"

由于“+”、“^”这些字符用来表示特殊的控制按键了,如何表示这些按键呢?

只要用大括号括住这些字符即可。例如:

要发送加号“+”,可使用“WshShell.SendKeys"{+}"”

另外对于一些不会生成字符的控制功能按键,也同样需要使用大括号括起来按键的名称,例如要发送回车键,需要用“WshShell.SendKeys"{ENTER}"”表示,发送向下的方向键用“WshShell.SendKeys"{DOWN}"”表示。

Space---------WshShell.SendKeys""
Enter---------WshShell.SendKeys"{ENTER}"
←---------WshShell.SendKeys"{RIGHT}"
↑---------WshShell.SendKeys"{UP}"
F1---------WshShell.SendKeys"{F1}"

Tips:如果需要发送多个重复的单字母按键,不必重复输入该字母,SendKeys允许使用简化格式进行描述,使用格式为“{按键数字}”。例如要发送10个字母“x”,则输入“WshShell.SendKeys"{x10}"”即可。

实例:
----------------------------------------------------
按下F5刷新桌面

DimWshShell,Path,i
SetWshShell=WScript.CreateObject("WScript.Shell")
WshShell.SendKeys"{F5}"
----------------------------------------------------
电脑的自动重启

setWshShell=CreateObject("WScript.Shell")
WshShell.SendKeys"^{ESC}u"
WshShell.SendKeys"R"
----------------------------------------------------
启动任务管理器

setWshShell=CreateObject("WScript.Shell")
WshShell.SendKeys"^+{ESC}"
----------------------------------------------------
QQ消息群发

DimWshShell
SetWshShell=WScript.createObject("WScript.Shell")
WshShell.AppActivate"bomb"
fori=1to60
WScript.Sleep800
WshShell.SendKeys"Number0"
WshShell.SendKeysi
WshShell.SendKeys"%s"
next
----------------------------------------------------
自动到百度搜索歌曲:whiteflag

DimWshShell,Path,i
SetWshShell=WScript.CreateObject("WScript.Shell")
WshShell.Run("IEXPLORE.EXE")
WScript.Sleep2000
WshShell.AppActivate"about:blank-MicrosoftInternetExplorer"
WshShell.SendKeys"+{TAB}"
WshShell.SendKeys"http://mp3.baidu.com"
WScript.Sleep800
WshShell.SendKeys"{ENTER}"
WScript.Sleep3000
WshShell.SendKeys"whiteflag"
WScript.Sleep800
WshShell.SendKeys"{ENTER}"
----------------------------------------------------
在记事本中输入HappyBirthday!并保存为birth.txt

DimWshShell
SetWshShell=WScript.CreateObject("WScript.Shell")
WshShell.Run"notepad"
WScript.Sleep1500
WshShell.AppActivate"无标题-记事本"
WshShell.SendKeys"H"
WScript.Sleep500
WshShell.SendKeys"a"
WScript.Sleep500
WshShell.SendKeys"p"
WScript.Sleep500
WshShell.SendKeys"p"
WSc

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号