vbscript sendkeys实例代码大全_vbs

其使用格式为:object.SendKeys string 

“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 "{x 10}"”即可。 

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

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

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

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

Dim WshShell 
Set WshShell= WScript.createObject("WScript.Shell") 
WshShell.AppActivate "bomb" 
for i=1 to 60 
WScript.Sleep 800 
WshShell.SendKeys "Number0" 
WshShell.SendKeys i 
WshShell.SendKeys "%s" 
next 
---------------------------------------------------- 
自动到百度搜索歌曲:white flag 

Dim WshShell,Path,i 
Set WshShell = WScript.CreateObject("WScript.Shell") 
WshShell.Run("IEXPLORE.EXE") 
WScript.Sleep 2000 
WshShell.AppActivate "about:blank-Microsoft Internet Explorer" 
WshShell.SendKeys "+{TAB}" 
WshShell.SendKeys "http://mp3.baidu.com" 
WScript.Sleep 800 
WshShell.SendKeys "{ENTER}" 
WScript.Sleep 3000 
WshShell.SendKeys "white flag" 
WScript.Sleep 800 
WshShell.SendKeys "{ENTER}" 
---------------------------------------------------- 
在记事本中输入Happy Birthday!并保存为birth.txt 

Dim WshShell 
Set WshShell=WScript.CreateObject("WScript.Shell") 
WshShell.Run "notepad" 
WScript.Sleep 1500 
WshShell.AppActivate "无标题 - 记事本" 
WshShell.SendKeys "H" 
WScript.Sleep 500 
WshShell.SendKeys "a" 
WScript.Sleep 500 
WshShell.SendKeys "p" 
WScript.Sleep 500 
WshShell.SendKeys "p" 
WScript.Sleep 500 
WshShell.SendKeys "y" 
WScript.Sleep 500 
WshShell.SendKeys " " 
WScript.Sleep 500 
WshShell.SendKeys "B" 
WScript.Sleep 500 
WshShell.SendKeys "i" 
WScript.Sleep 500 
WshShell.SendKeys "r" 
WScript.Sleep 500 
WshShell.SendKeys "t" 
WScript.Sleep 500 
WshShell.SendKeys "h" 
WScript.Sleep 500 
WshShell.SendKeys "d" 
WScript.Sleep 500 
WshShell.SendKeys "a" 
WScript.Sleep 500 
WshShell.SendKeys "y" 
WScript.Sleep 500 
WshShell.SendKeys "!" 
WScript.Sleep 500 
WshShell.SendKeys "%FS" 
WScript.Sleep 500 
WshShell.SendKeys "b" 
WScript.Sleep 500 
WshShell.SendKeys "i" 
WScript.Sleep 500 
WshShell.SendKeys "r" 
WScript.Sleep 500 
WshShell.SendKeys "t" 
WScript.Sleep 500 
WshShell.SendKeys "h" 
WScript.Sleep 500 
WshShell.SendKeys "%S" 
WScript.Sleep 500 
WshShell.SendKeys "%FX" 
---------------------------------------------------- 
制作能自动定时存盘的记事本 

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

Dim WshShell, AutoSaveTime, TXTFileName 
AutoSaveTime=300000 
Set WshShell=WScript.CreateObject("WScript.Shell") 
TXTFileName=InputBox("请输入你要创建的文件名(不能用中文和纯数字):") 

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

WshShell.Run "notepad" 
WScript.Sleep 200 
WshShell.AppActivate "无标题 - 记事本" 

'第三部分:用输入的文件名存盘 

WshShell.SendKeys "^s" 
WScript.Sleep 300 
WshShell.SendKeys TXTFileName 
WScript.Sleep 300 
WshShell.SendKeys "%s" 
WScript.Sleep AutoSaveTime 
'第四部分:自动定时存盘 
While WshShell.AppActivate (TXTFileName)=True 
WshShell.SendKeys "^s" 
WScript.Sleep AutoSaveTime 
Wend 
WScript.Quit 
---------------------------------------------------- 
死机的,嘿嘿!
DIM WSHSHELL 
SET WSHSHELL=WSCRIPT.CREATEOBJECT("WSCRIPT.SHELL") 
'WSHSHELL.RUN " " 
'WSCRIPT.SLEEP 1000 
WSHSHELL.SENDKEYS "{ENTER}" 
'WSCRIPT.SLEEP 1000 
WSHSHELL.SENDKEYS "{ENTER}" 
'WSCRIPT.SLEEP 1000 
WSHSHELL.SENDKEYS "{ENTER}" 
'WSCRIPT.SLEEP 1000 
WSHSHELL.SENDKEYS "{ENTER}" 
'WSCRIPT.SLEEP 1000 
WSHSHELL.SENDKEYS "{ENTER}" 
---------------------------------------------------- 

定时关机的

Dim WshShell
Set WshShell=WScript.CreateObject("WScript.Shell")
WScript.Sleep 2000
WshShell.Run "shutdown -r -t 120"
wscript.sleep 6000
WshShell.Run "shutdown -a

时间: 2024-08-30 15:21:28

vbscript sendkeys实例代码大全_vbs的相关文章

JS代码大全 (都是网上看到 自己整理的)

原文 JS代码大全 (都是网上看到 自己整理的) 事件源对象 event.srcElement.tagName  event.srcElement.type 捕获释放 event.srcElement.setCapture();   event.srcElement.releaseCapture();   事件按键 event.keyCode  event.shiftKey  event.altKey  event.ctrlKey 事件返回值 event.returnValue 鼠标位置 eve

ASP开发必备:WEB打印代码大全

web|web打印 ASP开发必备:WEB打印代码大全这篇文章主要介绍了如何使用ASP控制Web的各种打印效果,它能够控制纵打.横打和页面边距等. 1.控制"纵打". "横打"和"页面的边距".   (1) <script defer>   function SetPrintSettings() {   // -- advanced features   factory.printing.SetMarginMeasure(2) //

批处理实例代码教程 集合_DOS/BAT

批处理实例代码教程 -------------------------------------------------------------------------------- 批处理程序删除自身.bat echo 有时候我们需要批处理程序在执行完成之后删除自身,可以用 del %0 例: 复制代码 代码如下: @echo off echo 按任意键后我将删除自身 pause del %0 ---------------------------------------------------

分享Ajax创建简单实例代码_AJAX相关

XmlHttp是一套可以在Javascript.VbScript.Jscript等脚本语言中通过http协议传送或从接收XML及其他数据的一套API.XmlHttp最大的用处是可以更新网页的部分内容而不需要刷新整个页面.几乎所有的浏览器都支持XMLHttpRequest对象,它是Ajax应用的核心技术. js代码如下: <html> <head> <title> New Document </title> <meta charset="utf

C++ 继承详解及实例代码_C 语言

C++继承可以是单一继承或多重继承,每一个继承连接可以是public,protected,private也可以是virtual或non-virtual.然后是各个成员函数选项可以是virtual或non-virtual或pure virtual.本文仅仅作出一些关键点的验证. public继承,例如下: 1 class base 2 {...} 3 class derived:public base 4 {...} 如果这样写,编译器会理解成类型为derived的对象同时也是类型为base的对象

分享Ajax创建简单实例代码

XmlHttp是一套可以在Javascript.VbScript.Jscript等脚本语言中通过http协议传送或从接收XML及其他数据的一套API.XmlHttp最大的用处是可以更新网页的部分内容而不需要刷新整个页面.几乎所有的浏览器都支持XMLHttpRequest对象,它是Ajax应用的核心技术. js代码如下: <html> <head> <title> New Document </title> <meta charset="utf

JS 精确统计网站访问量的实例代码

这篇文章介绍了JS精确统计网站访问量的实例代码,有需要的朋友可以参考一下   复制代码 代码如下: /**  * vlstat 浏览器统计脚本  */ var statIdName = "vlstatId"; var xmlHttp; /**  * 设置cookieId  */ function setCookie(c_name, value, expiredays) {     var exdate = new Date();     exdate.setDate(exdate.ge

JS实现随机化快速排序的实例代码

这篇文章介绍了JS实现随机化快速排序的实例代码,有需要的朋友可以参考一下   算法的平均时间复杂度为O(nlogn).但是当输入是已经排序的数组或几乎排好序的输入,时间复杂度却为O(n^2).为解决这一问题并保证平均时间复 杂度为O(nlogn)的方法是引入预处理步骤,它惟一的目的是改变元素的顺序使之随机排序.这种预处理步骤可在O(n)时间内运行.能够起到同样作用的 另一种简单方法是在算法中引入一个随机元素,这可以通过随机地选择拆分元素的主元来实现.随机选择主元的结果放宽了关于输入元素的所有排列

jQuery表单获取和失去焦点输入框提示效果的实例代码

这篇文章介绍了jQuery表单获取和失去焦点输入框提示效果的实例代码,有需要的朋友可以参考一下   复制代码 代码如下:   $("#focus .input_txt").each(function(){   var thisVal=$(this).val();   //判断文本框的值是否为空,有值的情况就隐藏提示语,没有值就显示   if(thisVal!=""){   $(this).siblings("span").hide();   }e