wshShell.SendKeys模拟键盘操作
Dim wshShell
Set wshShell = CreateObject("Wscript.Shell")
wshShell.SendKeys "{ENTER}" '模拟键盘操作回车
1.基本键
一般来说,要发送的按键指令都可以直接用该按键字符本身来表示,例如要发送字母“x”,使用“WshShell.SendKeys "x"”即可。当然,也可直接发送多个按键指令,只需要将按键字符按顺序排列在一起即可,例如,要发送按键“happy”,可以使用“ WshShell.SendKeys "happy" ”。
2.特殊功能键
对于需要与Shift、Ctrl、Alt三个控制键组合的按键,SendKeys使用特殊字符来表示:
Shift---------WshShell.SendKeys "+"
Ctrl---------WshShell.SendKeys "^"
Alt---------WshShell.SendKeys "%" (注意:这样使用时,不用大括号括起这些特殊字符。)
由于“+”、“^”这些字符用来表示特殊的控制按键了,如何表示这些”字符”的按键呢?只要用大括号括住这些字符即可。例如: 要发送加号“+”,可使用“WshShell.SendKeys "{+}"”
另外对于一些不会生成字符的控制功能按键,也同样需要使用大括号括起来按键的名称。--如果发送是基本字符用“”括起来。
例如要发送回车键,需要用“ WshShell.SendKeys "{ENTER}" ”表示;
发送向下的方向键用“ Wshshell.SendKeys "{DOWN}" ”表示。
Space---------WshShell.SendKeys " "
Enter---------WshShell.SendKeys "{ENTER}"
←---------WshShell.SendKeys "{RIGHT}"
↑---------WshShell.SendKeys "{UP}"
F1---------WshShell.SendKeys "{F1}"
按键 代码
BACKSPACE {BACKSPACE}, {BS}, 或 {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL or Delete {Delete} 或 {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER {ENTER}或 ~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS or Insert {Insert} 或 {INS}
LEFT ARROW {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
PRINT SCREEN {PRTSC}
RIGHT ARROW {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
UP ARROW {UP}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
Tips:如果需要发送多个重复的单字母按键,不必重复输入该字母,SendKeys允许使用简化格式进行描述,使用格式为“{按键 数字}”。例如要发送10个字母“x”,则输入“WshShell.SendKeys "{x 10}"”即可。
为了说明在按下其它按键时应同时按下 SHIFT、CTRL、及 ALT 的任意组合键,请把那些按键的码放在括号当中。例如,为了说明按下 E 与 C 的时候同时按下 SHIFT 键,请使用 "+(EC)"。为了说明在按下 E 的时候同时按下 SHIFT 键,但接着按 C 而不按 SHIFT,则使用 "+EC"。
实际应用举例: ----------------------------------- 按下F5刷新桌面
Dim WshShell,Path,i Set WshShell = Wscrīpt.CreateObject("Wscrīpt.Shell") WshShell.SendKeys "{F5}" ---------------------------------------------------- 电脑的自动重启
set WshShell = CreateObject("Wscrīpt.Shell") WshShell.SendKeys "^{ESC}u" WshShell.SendKeys "R" ---------------------------------------------------- 启动任务管理器
set WshShell = CreateObject("Wscrīpt.Shell") WshShell.SendKeys "^+{ESC}" ---------------------------------------------------- QQ消息连发
Dim WshShell Set WshShell= Wscrīpt.createObject("Wscrīpt.Shell") WshShell.AppActivate "bomb" for i=1 to 60 Wscrīpt.Sleep 800 WshShell.SendKeys "What do you say" WshShell.SendKeys i WshShell.SendKeys "%s" next ---------------------------------------------------- 自动到百度搜索歌曲:white flag
Dim WshShell,Path,i Set WshShell = Wscrīpt.CreateObject("Wscrīpt.Shell") WshShell.Run("IEXPLORE.EXE") Wscrīpt.Sleep 2000 WshShell.AppActivate "about:blank-Microsoft Internet Explorer" WshShell.SendKeys "+{TAB}" WshShell.SendKeys "http://mp3.baidu.com" Wscrīpt.Sleep 800 WshShell.SendKeys "{ENTER}" Wscrīpt.Sleep 3000 WshShell.SendKeys "white flag" Wscrīpt.Sleep 800 WshShell.SendKeys "{ENTER}" ---------------------------------------------------- 自动关机
Dim WshShell Set WshShell=Wscrīpt.CreateObject("Wscrīpt.Shell") Wscrīpt.Sleep 2000 WshShell.Run "shutdown -r -t 120" wscrīpt.sleep 6000 WshShell.Run "shutdown -a" ---------------------------------------------------- 在记事本中输入Happy Birthday!并保存为birth.txt
Dim WshShell Set WshShell=Wscrīpt.CreateObject("Wscrīpt.Shell") WshShell.Run "notepad" Wscrīpt.Sleep 1500 WshShell.AppActivate "无标题 - 记事本" WshShell.SendKeys "H" Wscrīpt.Sleep 500 WshShell.SendKeys "a" Wscrīpt.Sleep 500 WshShell.SendKeys "p" Wscrīpt.Sleep 500 WshShell.SendKeys "p" Wscrīpt.Sleep 500 WshShell.SendKeys "y" Wscrīpt.Sleep 500 WshShell.SendKeys " " Wscrīpt.Sleep 500 WshShell.SendKeys "B" Wscrīpt.Sleep 500 WshShell.SendKeys "i" Wscrīpt.Sleep 500 WshShell.SendKeys "r" Wscrīpt.Sleep 500 WshShell.SendKeys "t" Wscrīpt.Sleep 500 WshShell.SendKeys "h" Wscrīpt.Sleep 500 WshShell.SendKeys "d" Wscrīpt.Sleep 500 WshShell.SendKeys "a" Wscrīpt.Sleep 500 WshShell.SendKeys "y" Wscrīpt.Sleep 500 WshShell.SendKeys "!" Wscrīpt.Sleep 500 WshShell.SendKeys "%FS" Wscrīpt.Sleep 500 WshShell.SendKeys "b" Wscrīpt.Sleep 500 WshShell.SendKeys "i" Wscrīpt.Sleep 500 WshShell.SendKeys "r" Wscrīpt.Sleep 500 WshShell.SendKeys "t" Wscrīpt.Sleep 500 WshShell.SendKeys "h" Wscrīpt.Sleep 500 WshShell.SendKeys "%S" Wscrīpt.Sleep 500 WshShell.SendKeys "%FX" ---------------------------------------------------- 制作能自动定时存盘的记事本
'第一部分:定义变量和对象
Dim WshShell, AutoSaveTime, TXTFileName AutoSaveTime=300000 Set WshShell=Wscrīpt.CreateObject("Wscrīpt.Shell") TXTFileName=InputBox("请输入你要创建的文件名(不能用中文和纯数字):")
'第二部分:打开并激活记事本
WshShell.Run "notepad" Wscrīpt.Sleep 200 WshShell.AppActivate "无标题 - 记事本"
'第三部分:用输入的文件名存盘
WshShell.SendKeys "^s" Wscrīpt.Sleep 300 WshShell.SendKeys TXTFileName Wscrīpt.Sleep 300 WshShell.SendKeys "%s" Wscrīpt.Sleep AutoSaveTime '第四部分:自动定时存盘 While WshShell.AppActivate (TXTFileName)=True WshShell.SendKeys "^s" Wscrīpt.Sleep AutoSaveTime Wend Wscrīpt.Quit
----------------------------------------------------
自动死机o(∩_∩)o...
DIM WSHSHELL SET WSHSHELL=Wscrīpt.CreateOBJECT("Wscrīpt.SHELL") 'WSHSHELL.RUN " " 'Wscrīpt.SLEEP 1000 WSHSHELL.SENDKEYS "{ENTER}" 'Wscrīpt.SLEEP 1000 WSHSHELL.SENDKEYS "{ENTER}" 'Wscrīpt.SLEEP 1000 WSHSHELL.SENDKEYS "{ENTER}" 'Wscrīpt.SLEEP 1000 WSHSHELL.SENDKEYS "{ENTER}" 'Wscrīpt.SLEEP 1000 WSHSHELL.SENDKEYS "{ENTER}"
wshShell.SendKeys模拟键盘操作的更多相关文章
- firefox下载文件弹出框之终极解决方案-vbs模拟键盘操作
由于近期一直被firefox的保存文件弹出框困扰,摸索尝试过几种方法,已有的方法可以跑通但是对对效果不太满意,因此一直在寻找合适的解决办法. 最近发现了也可以通过VBS来处理弹出框,速度也不错,其原理 ...
- 【java+selenium3】模拟键盘操作 (十二)
一.键盘操作 用代码来模拟键盘的Enter或一系列的组合键,前面使用sendkeys()方法模拟键盘的输入,除此之外还可以模拟键盘组合键输入如下: 整理一些比较常用的键盘操作如下: sendKeys( ...
- Python+Selenium自动化-模拟键盘操作
Python+Selenium自动化-模拟键盘操作 0.导入键盘类Keys() selenium中的Keys()类提供了大部分的键盘操作方法:通过send_keys()方法来模拟键盘上的按键. # ...
- C# 模拟键盘操作--SendKey(),SendKeys()
模拟键盘输入就是使用以下2个语法实现的.SendKeys.Send(string keys); //模拟汉字(文本)输入SendKeys.SendWait(string keys); //模拟按键输 ...
- C# 模拟键盘操作SendKey(),SendKeys()
模拟键盘输入就是使用以下2个语法实现的. SendKeys.Send(string keys); //模拟汉字(文本)输入SendKeys.SendWait(string keys); //模拟按键 ...
- selenium模拟键盘操作
单键 /** * 模拟键盘回车事件 * @throws AWTException */ public void KeyEventEnter() throws AWTException { Robot ...
- Selenium WebDriver-actionchain模拟键盘操作
#encoding=utf-8 import unittest import time import chardet from selenium import webdriver from selen ...
- SendInput模拟键盘操作
#include <windows.h> int main() { HWND parentHwnd, childHwnd; INPUT input[4]; parentHwnd = Fin ...
- UI自动化测试(四)AutoIT工具使用和robot对象模拟键盘按键操作
AutoIT简介 AutoIt 目前最新是v3版本,这是一个使用类似BASIC脚本语言的免费软件,它设计用于Windows GUI(图形用户界面)中进行自动化操作.它利用模拟键盘按键,鼠标移动和窗口/ ...
随机推荐
- JavaScript获取当前站点的域名和端口号
获取域名(第一种方法): document.hostname 获取域名(第二种方法): document.domin 获取端口号: location.port 获取主机+端口号: location.h ...
- node.js缓存处理方式
Node.JS缓存处理分为客户端和服务端两个部分. 客户端的缓存主要是利用浏览器对HTTP协议响应头中cache-control和expires字段的支持.浏览器在得到明确的响应头后,会将文件缓存在本 ...
- C Primer Plus note5
error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token| 遇到这种情况,不要看这里显示了三个错误,就很着急.静 ...
- Incorrect column count: expected 1, actual 5
在使用jdbc的querForObject queryForList的时候,出现Incorrect column count: expected 1, actual 5 比如 String sql = ...
- Html5本地存储+本地数据库+离线存储
首先介绍什么叫存储: cache:通常把它叫做缓存,功能就是把从DB,或者磁盘拿出来的东西放在缓存里面,这样的话可以减少读取磁盘的IO. 磁盘文件:通常把一些图片或者一些视频都存放在磁盘上. 数据库: ...
- jQuery Text-to-Speech 谷歌在线语音
<!DOCTYPE html> <html> <head> <meta content="text/html; charset=utf-8" ...
- mysql if函数使用例子
1.场景一 有时查询数量a 同时查询过滤后的数量b 2. 代码 SELECT count(id) as total_count, count( IF ( date(order_time) = DATE ...
- MySQL库表详细操作
昨天我们初始了MySQL,今天我们先从库表方面详细说一下具体操作 一.库操作 1.创建数据库 1.1 语法 CREATE DATABASE 数据库名 charset utf8; 1.2 数据库命名规则 ...
- Apache服务器运维笔记(2)----使用<IfDefine>容器实现不同的配置
还有一种方法用来实现不同配置的Apache服务器启动,就是在一个配置文件中使用<IfDefine name> ... </IfDefine> 容器来定义,在<IfDefi ...
- 第9课 备忘便签-TinyDB
编写一只个性化的App便签小程序,TinyDB可能会帮上你. 1.组件设计 1)TextBox1输入需要记录存储的信息记录 2)四只button分别作为“添加 编辑 删除清空”信息记录 3)Lli ...