' ======================================
' 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
' ======================================
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
-
-
-
-
用vbs实现文本循环读取
因为测试中需要读取一批url数据进行浏览,其实使用qtp本身的table能实现多种读取方式,但是因为需要tabel是使用excel保存的,在没有...
[阅读全文]
-
-
-
-
-
网友评论