QTP模拟键盘操作代码
上一篇 / 下一篇 2011-10-19 16:01:02 / 天气: 舒适 / 心情: 高兴 / 置顶(1) / 个人分类:qtp学习
Set wshShell = CreateObject("Wscript.Shell")
其使用格式为:object.SendKeys(string)
“object”:表示WshShell对象
“string”:表示要发送的按键指令字符串,需要放在英文双引号中。
Dim wshShell
Set wshShell = CreateObject("Wscript.Shell")
wshShell.SendKeys "{ENTER}"
-----------------------------------
1.基本键
一般来说,要发送的按键指令都可以直接用该按键字符本身来表示,例如要发送字母“x”,使用“WshShell.SendKeys
2.特殊功能键
对于需要与Shift、Ctrl、Alt三个控制键组合的按键,SendKeys使用特殊字符来表示:
Shift---------WshShell.SendKeys
Ctrl---------WshShell.SendKeys
Alt---------WshShell.SendKeys
由于“+”、“^”这些字符用来表示特殊的控制按键了,如何表示这些”字符”的按键呢?只要用大括号括住这些字符即可。例如:
另外对于一些不会生成字符的控制功能按键,也同样需要使用大括号括起来按键的名称。--如果发送是基本字符用“”括起来。
例如要发送回车键,需要用“
发送向下的方向键用“
Space---------WshShell.SendKeys
Enter---------WshShell.SendKeys
←---------WshShell.SendKeys
↑---------WshShell.SendKeys
F1---------WshShell.SendKeys
按键
BACKSPACE
BREAK
CAPS
DEL
DOWN
END
ENTER
ESC
HELP
HOME
INS
LEFT
NUM
PAGE
PAGE
PRINT
RIGHT
SCROLL
TAB
UP
F1
F2
F3
F4
F5
F6
F7
F8
F9
F10
Tips:如果需要发送多个重复的单字母按键,不必重复输入该字母,SendKeys允许使用简化格式进行描述,使用格式为“{按键
实际应用举例:
-----------------------------------
按下F5刷新桌面
Dim
Set
WshShell.SendKeys
----------------------------------------------------
电脑的自动重启
set
WshShell.SendKeys
WshShell.SendKeys
----------------------------------------------------
启动任务管理器
set
WshShell.SendKeys
----------------------------------------------------
QQ消息连发
Dim
Set
WshShell.AppActivate
for
Wscrīpt.Sleep
WshShell.SendKeys
WshShell.SendKeys
WshShell.SendKeys
next
----------------------------------------------------
自动到百度搜索歌曲:white
Dim
Set
WshShell.Run("IEXPLORE.EXE")
Wscrīpt.Sleep
WshShell.AppActivate
WshShell.SendKeys
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
----------------------------------------------------
自动关机
Dim
Set
Wscrīpt.Sleep
WshShell.Run
wscrīpt.sleep
WshShell.Run
----------------------------------------------------
在记事本中输入Happy
Dim
Set
WshShell.Run
Wscrīpt.Sleep
WshShell.AppActivate
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
----------------------------------------------------
制作能自动定时存盘的记事本
'第一部分:定义变量和对象
Dim
AutoSaveTime=300000
Set
TXTFileName=InputBox("请输入你要创建的文件名(不能用中文和纯数字):")
'第二部分:打开并激活记事本
WshShell.Run
Wscrīpt.Sleep
WshShell.AppActivate
'第三部分:用输入的文件名存盘
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
WshShell.SendKeys
Wscrīpt.Sleep
'第四部分:自动定时存盘
While
WshShell.SendKeys
Wscrīpt.Sleep
Wend
Wscrīpt.Quit
----------------------------------------------------
自动死机o(∩_∩)o...
DIM
SET
'WSHSHELL.RUN
'Wscrīpt.SLEEP
WSHSHELL.SENDKEYS
'Wscrīpt.SLEEP
WSHSHELL.SENDKEYS
'Wscrīpt.SLEEP
WSHSHELL.SENDKEYS
'Wscrīpt.SLEEP
WSHSHELL.SENDKEYS
'Wscrīpt.SLEEP
WSHSHELL.SENDKEYS
TAG:
标题搜索
日历
|
|||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
1 | 2 | 3 | 4 | ||||||
5 | 6 | 7 | 8 | 9 | 10 | 11 | |||
12 | 13 | 14 | 15 | 16 | 17 | 18 | |||
19 | 20 | 21 | 22 | 23 | 24 | 25 | |||
26 | 27 | 28 | 29 | 30 | 31 |
我的存档
数据统计
- 访问量: 18493
- 日志数: 42
- 建立时间: 2011-03-23
- 更新时间: 2012-03-13