宝峰科技

 找回密码
 注册

QQ登录

只需一步,快速开始

智能终端设备维修查询系统注册会员邮箱认证须知!
查看: 5917|回复: 2

[VB基础知识] VB6中SendKeys的用法

[复制链接]
  • TA的每日心情
    奋斗
    2020-6-5 22:18
  • 签到天数: 22 天

    [LV.4]偶尔看看III

    潇潇 发表于 2010-11-15 00:16:09 | 显示全部楼层 |阅读模式

    欢迎您注册加入!这里有您将更精采!

    您需要 登录 才可以下载或查看,没有账号?注册

    x
    SendKeys :模拟键盘操作,将一个或多个按键指令发送到指定Windows窗口来控制应用程序运行,  
    其使用格式为:object.SendKeys string  
    “object”:表示WshShell对象  
    “string”:表示要发送的按键指令字符串,需要放在英文双引号中。  
    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}"  
    Tips:如果需要发送多个重复的单字母按键,不必重复输入该字母,SendKeys允许使用简化格式进行描述,使用格式为“{按键 数字}”。例如要发送10个字母“x”,则输入“WshShell.SendKeys "{x 10}"”即可。  
    实例:
    [Visual Basic] 纯文本查看 复制代码
    ---------------------------------------------------- 
    按下F5刷新桌面 
    Dim WshShell,Path,i 
    Set WshShell = WScript.CreateObject("WScript.Shell") 
    WshShell.SendKeys "{F5}" 
    ---------------------------------------------------- 
    电脑的自动重启 
    set WshShell = CreateObject("WScript.Shell") 
    WshShell.SendKeys "^{ESC}u" 
    WshShell.SendKeys "R" 
    ---------------------------------------------------- 
    启动任务管理器 
    set WshShell = CreateObject("WScript.Shell") 
    WshShell.SendKeys "^+{ESC}" 
    ---------------------------------------------------- 
    QQ消息群发 
    Dim WshShell 
    Set WshShell= WScript.createObject("WScript.Shell") 
    WshShell.AppActivate "bomb" 
    for i=1 to 60 
    WScript.Sleep 800 
    WshShell.SendKeys "Number0" 
    WshShell.SendKeys i 
    WshShell.SendKeys "%s" 
    next 
    ---------------------------------------------------- 
    自动到百度搜索歌曲:white flag 
    Dim WshShell,Path,i 
    Set WshShell = WScript.CreateObject("WScript.Shell") 
    WshShell.Run("IEXPLORE.EXE") 
    WScript.Sleep 2000 
    WshShell.AppActivate "about:blank-Microsoft Internet Explorer" 
    WshShell.SendKeys "+{TAB}" 
    WshShell.SendKeys "http://mp3.baidu.com" 
    WScript.Sleep 800 
    WshShell.SendKeys "{ENTER}" 
    WScript.Sleep 3000 
    WshShell.SendKeys "white flag" 
    WScript.Sleep 800 
    WshShell.SendKeys "{ENTER}" 
    ---------------------------------------------------- 
    在记事本中输入Happy Birthday!并保存为birth.txt 
    Dim WshShell 
    Set WshShell=WScript.CreateObject("WScript.Shell") 
    WshShell.Run "notepad" 
    WScript.Sleep 1500 
    WshShell.AppActivate "无标题 - 记事本" 
    WshShell.SendKeys "H" 
    WScript.Sleep 500 
    WshShell.SendKeys "a" 
    WScript.Sleep 500 
    WshShell.SendKeys "p" 
    WScript.Sleep 500 
    WshShell.SendKeys "p" 
    WScript.Sleep 500 
    WshShell.SendKeys "y" 
    WScript.Sleep 500 
    WshShell.SendKeys " " 
    WScript.Sleep 500 
    WshShell.SendKeys "B" 
    WScript.Sleep 500 
    WshShell.SendKeys "i" 
    WScript.Sleep 500 
    WshShell.SendKeys "r" 
    WScript.Sleep 500 
    WshShell.SendKeys "t" 
    WScript.Sleep 500 
    WshShell.SendKeys "h" 
    WScript.Sleep 500 
    WshShell.SendKeys "d" 
    WScript.Sleep 500 
    WshShell.SendKeys "a" 
    WScript.Sleep 500 
    WshShell.SendKeys "y" 
    WScript.Sleep 500 
    WshShell.SendKeys "!" 
    WScript.Sleep 500 
    WshShell.SendKeys "%FS" 
    WScript.Sleep 500 
    WshShell.SendKeys "b" 
    WScript.Sleep 500 
    WshShell.SendKeys "i" 
    WScript.Sleep 500 
    WshShell.SendKeys "r" 
    WScript.Sleep 500 
    WshShell.SendKeys "t" 
    WScript.Sleep 500 
    WshShell.SendKeys "h" 
    WScript.Sleep 500 
    WshShell.SendKeys "%S" 
    WScript.Sleep 500 
    WshShell.SendKeys "%FX" 
    ---------------------------------------------------- 
    制作能自动定时存盘的记事本 
    '第一部分:定义变量和对象 
    Dim WshShell, AutoSaveTime, TXTFileName 
    AutoSaveTime=300000 
    Set WshShell=WScript.CreateObject("WScript.Shell") 
    TXTFileName=InputBox("请输入你要创建的文件名(不能用中文和纯数字):") 
    '第二部分:打开并激活记事本 
    WshShell.Run "notepad" 
    WScript.Sleep 200 
    WshShell.AppActivate "无标题 - 记事本" 
    '第三部分:用输入的文件名存盘 
    WshShell.SendKeys "^s" 
    WScript.Sleep 300 
    WshShell.SendKeys TXTFileName 
    WScript.Sleep 300 
    WshShell.SendKeys "%s" 
    WScript.Sleep AutoSaveTime 
    '第四部分:自动定时存盘 
    While WshShell.AppActivate (TXTFileName)=True 
    WshShell.SendKeys "^s" 
    WScript.Sleep AutoSaveTime 
    Wend 
    WScript.Quit 
    ---------------------------------------------------- 
    死机的,嘿嘿! 
    DIM WSHSHELL 
    SET WSHSHELL=WSCRIPT.CreateOBJECT("WSCRIPT.SHELL") 
    'WSHSHELL.RUN " " 
    'WSCRIPT.SLEEP 1000 
    WSHSHELL.SENDKEYS "{ENTER}" 
    'WSCRIPT.SLEEP 1000 
    WSHSHELL.SENDKEYS "{ENTER}" 
    'WSCRIPT.SLEEP 1000 
    WSHSHELL.SENDKEYS "{ENTER}" 
    'WSCRIPT.SLEEP 1000 
    WSHSHELL.SENDKEYS "{ENTER}" 
    'WSCRIPT.SLEEP 1000 
    WSHSHELL.SENDKEYS "{ENTER}" 
    ---------------------------------------------------- 
    定时关机的 
    Dim WshShell 
    Set WshShell=WScript.CreateObject("WScript.Shell") 
    WScript.Sleep 2000 
    WshShell.Run "shutdown -r -t 120" 
    wscript.sleep 6000 
    WshShell.Run "shutdown -a”

  • TA的每日心情
    开心
    2012-7-29 00:25
  • 签到天数: 6 天

    [LV.2]偶尔看看I

    花心胡萝卜 发表于 2010-11-30 09:51:35 | 显示全部楼层
    其实老大,sendkeys可以发送字符串的,Sendkeys "Happy Birthdy!"也是可以的
  • TA的每日心情
    开心
    2012-4-18 06:53
  • 签到天数: 1 天

    [LV.1]初来乍到

    nwfoaf 发表于 2012-1-17 23:31:38 | 显示全部楼层
    老大,我用sendkeys发送shift怎么不好用呢
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    免责声明

    本站中所有被研究的素材与信息全部来源于互联网,版权争议与本站无关。本站所发布的任何软件编程开发或软件的逆向分析文章、逆向分析视频、补丁、注册机和注册信息,仅限用于学习和研究软件安全的目的。全体用户必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。学习编程开发技术或逆向分析技术是为了更好的完善软件可能存在的不安全因素,提升软件安全意识。所以您如果喜欢某程序,请购买注册正版软件,获得正版优质服务!不得将上述内容私自传播、销售或者用于商业用途!否则,一切后果请用户自负!

    QQ|Archiver|手机版|小黑屋|联系我们|宝峰科技 ( 滇公网安备 53050202000040号 | 滇ICP备09007156号-2 )

    Copyright © 2001-2023 Discuz! Team. GMT+8, 2024-12-22 12:35 , File On Powered by Discuz! X3.49

    快速回复 返回顶部 返回列表