当前位置: 移动技术网 > IT编程>脚本编程>VBScript > VBS sendkeys 模拟击键操作 问题解决

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

2017年12月08日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:

' ======================================
' 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
' ======================================

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网