标题 | VBS sendkeys 模拟击键操作 问题解决 |
内容 | 今天有人问我如何向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 ' ====================================== |
随便看 |
|
在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。