SendKeys

模拟键盘操作,将一个或多个按键指令发送到指定Windows窗口来控制应用程序运行,

其使用格式为: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

转自:枕善居


更多精彩>>>

VB6中SendKeys的基本应用相关推荐

  1. VB6中给数组赋值的限制

    (由于用得不是很多,所以干脆记下来免得下次用到时又忘了.) MSDN有个错误是"不能给数组赋值",即不能将整个数组指定给另一个数组. 而实际上有时行,有时又不行,刚刚写代码时又遇到 ...

  2. vb6中使text控件的光标随着增加的内容向下移动

    vb6中使text控件的光标随着增加的内容向下移动 Dim i As Integer Private Sub Command1_Click() Text1.Text = Text1.Text + &q ...

  3. VB6中如何使用C#开发的WebService进行开发

    VB6中如何使用C#开发的WebService进行开发<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office ...

  4. 发现VB6中SAX的乐趣[转]

    发现VB6中SAX的乐趣 http://www.techng.com/content.aspx?titleid=5748 微软公司的XML核服务(Core Services),也就是广为人知的MSXM ...

  5. VB6 中 善用 ByRef 提升速度

    和.Net 中不同,VB6 中默认是使用 ByRef 来传递参数了,看来似乎没有什么可以优化得地方. 可是,实际上 如果你调用 API 得话,从 API浏览器复制下来得代码却是 强制使用 ByVal ...

  6. 在VB6中生成随机数

    VB6版本 在VB6中生成随机数有些不同. 我不说哪个更好,因为我只熟悉VB6方法. 但是肯定会产生一个随机数(更正确地说是一个伪随机数)是 在VB6中更简单 . 您只需调用Rnd()函数. 此示例表 ...

  7. 最多只需三步,彻底解决VB6中不能加载MSCOMCTL.OCX的提示

    在打开很多使用VB6开发的软件(系统)工程文件(源代码)时,经常会遇到"不能加载MSCOMCTL.OCX"的错误提示,如图所示(此处以本店开发的一个系统为例进行讲解): 在上图中点 ...

  8. vb6调用python识别训练例子_在vb6中创建的“标准”dll在python中调用时会出现访问冲突...

    从vb6dll导出函数的最简单方法是使用vbAdvance add-in,现在它是免费软件.在 您面临的问题是,您需要在调用导出的线程上初始化VB6运行时.这包括初始化COM单元(STA).最简单的方 ...

  9. VB6中的面向对象编程---实现类继承

    确切地说VB6不能实现真正意义上的类继承(如C++中的继承),但是通过其关键字Implements也提供了类似的功能. 我们先建一个类模块CBase.cls 代码如下: Private mvarBas ...

最新文章

  1. 如何插入页面,PDF怎么插入页面
  2. linux编译mysql报无法将左值_'错误:无法将'std::ostream {aka std::basic_ostream
  3. python在画布上写文字大小_Tkinter:在画布上缩放项目
  4. Leetcode题库 110.平衡二叉树(递归 C实现)
  5. Redis中的Sentinel 验证
  6. 二叉树的遍历java版本
  7. bootstrap的分页
  8. System variables, logging and the Execute SQL Task...(zz)
  9. 【C++ STL学习之三】容器deque深入学习
  10. subd计算机系统结构,计算机体系结构第2章试题答案.doc
  11. 【精心挑选】推荐几款非常棒的 jQuery 全景图片展示插件
  12. AIMS 2013中的性能报告工具不能运行的解决办法
  13. Chapter 5 : 索引和算法
  14. 注册ActiveX控件 未在此计算机上注册ActiveX控件!!!
  15. 三级等级保护之安全管理中心
  16. 【Spring基础】CGLIB动态代理实现原理
  17. MySQL卸载教程 (Windows版)
  18. 查询中国天气网api需要用到的城市代码
  19. CSS基础的文字样式
  20. 使用cmd命令行查看wifi密码

热门文章

  1. 漫画:996 的本质是什么?
  2. “边缘计算将吞掉云计算!”
  3. 为何要弃 Java、Swift 于不顾,而选择 Python?
  4. 华为三星折叠手机可看不可摸;小米架构再调整;杨幂 AI 换脸视频制作者回应 | 极客头条...
  5. 死磕shell系列-shell介绍
  6. 数据结构与算法顺序表数组版
  7. day04【后台】角色维护
  8. python如何使用sdk_Python_sdk首页、文档和下载 - 优图人脸识别sdk - OSCHINA - 中文开源技术交流社区...
  9. springboot做网站_Github点赞接近 100k 的Spring Boot学习教程+实战项目推荐!
  10. 数据增强_NLP 数据增强方法 EDA