首页 电脑 电脑学堂 查看内容

VBS sendkeys 模拟击键操作 问题解决

2009-9-23 17:16 865 0

摘要:   今天有人问我如何向APPlication 发送双引号,分号等,我在这里做一个总结,方便你使用参考   代码如下:   ' ===================================...

  今天有人问我如何向APPlication 发送双引号,分号等,我在这里做一个总结,方便你使用参考   代码如下:   ' ======================================   ' VBS 中 SendKeys 模拟键盘击键   ' 2009-07-26   ' 刘林   ' ======================================   Dim WshShell   Set WshShell=WScript.CreateObject("WScript.Shell")   WshShell.Run "cmd"   ' 让脚本等待1000毫秒,也就是1秒再执行下一条语句   WScript.Sleep 1000   ' -- 发送字符时,输入法一定要在英文件状态下   ' 发送分号   WshShell.SendKeys ";"   WScript.Sleep 1000   ' 发送冒号   WshShell.SendKeys ":"   WScript.Sleep 1000   ' 发送双引号 -- 利用chr把双引号转换出来   WshShell.SendKeys Chr(34)   WScript.Sleep 1000   ' 发送带有双引号的字符串   WshShell.SendKeys Chr(34)&"this is a string"&Chr(34)   WScript.Sleep 1000   ' -- 切记,这里是模拟的击键操作,所以不能发送中文   'WshShell.SendKeys Chr(34)&"这是一个字符串"&Chr(34)   WScript.Sleep 1000   ' ================================================   ' -- 如何模拟回车,上档键,Alt键喃?   ' ================================================   ' -- 如何模拟回车, -- {enter}这就代表是发送回车   WshShell.SendKeys "this is a enter!{enter}"   WScript.Sleep 1000   ' -- 如何模拟上档键Shift, -- +这就代表是发送shift   WshShell.SendKeys "this is +a" ' 结果为 this is A   WScript.Sleep 1000   ' -- 如何模拟Alt, -- %这就代表是发送Alt   WshShell.SendKeys "this is %{TAB}" ' 结果为 切换窗口   WScript.Sleep 1000   ' ===========================================================   ' -- 那么如何发送%, + ^ 喃   WshShell.SendKeys "this is {+}{^}{%}" ' 结果为 切换窗口   WScript.Sleep 1000   ' -- 这里你可能已经明白了,发送送特殊字符时,请放到 {} 中   ' ===========================================================   ' ======================================   ' 更多信息请看VBS帮助文档 2009-07-26   ' ======================================
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部