zoukankan      html  css  js  c++  java
  • 解决在CAPSLOCK开启情况下sendkeys大小写异常的问题

    http://files.cnblogs.com/files/liuzhaoyzz/sendkeys%E5%A4%A7%E5%B0%8F%E5%86%99.rar

    首先利用GetKeyState(vbKeyCapital) 的API获取capslock的状态,如果开启了,就SendKeys "{capslock}",

    然后SendKeys "s",这样子的语句,默认=SendKeys "s",false的,如果操作其他程序,最后一个sendkeys之后,

    必须用doevents交还控制权。试试看下面的代码在CAPSLOCK开启和关闭状态下的情况。

    所以最好还是要用SendKeys "s",false,会获得你想要的结果,这也是sendkeys的默认值。

    Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
    Private Sub Command1_Click()
    If GetKeyState(vbKeyCapital) = 1 Then
    SendKeys "{capslock}"
    End If
    Text1.SetFocus
    SendKeys "s"
    ' SendKeys "{CAPSLOCK}" ' Turn on the CapsLock
    SendKeys "o" ' will be printed in caps
    For i = 0 To 10
    SendKeys Chr(Asc("A") + i) 'will be printed in caps
    Next
    'DoEvents ' uncommenting this will print next line in smalls
    SendKeys "o" ' will be printed in caps
    ' SendKeys "{CAPSLOCK}" ' Turn off the caps lock
    SendKeys "o" ' Will be printed in smalls
    End Sub

    Private Sub Command2_Click()
    If GetKeyState(vbKeyCapital) = 1 Then
    SendKeys "{capslock}"
    End If

    Text1.SetFocus
    SendKeys "s", True
    ' SendKeys "{CAPSLOCK}", True ' Turn on the CapsLock
    SendKeys "o", True ' will be printed in caps
    For i = 0 To 10
    SendKeys Chr(Asc("A") + i), True 'will be printed in caps
    Next
    'DoEvents ' uncommenting this will print next line in smalls
    SendKeys "o", True ' will be printed in caps
    ' SendKeys "{CAPSLOCK}", True ' Turn off the caps lock
    SendKeys "o", True ' Will be printed in smalls
    End Sub

    Private Sub Command3_Click()
    Text1 = ""
    End Sub

  • 相关阅读:
    ckfinder+ckeditor配置经验
    人人商城模块研究
    微擎小程序支付功能+退款功能
    php服务器网络请求
    linux对workerman的扩展和配置
    linux安装php_screw加密php代码
    webForm渲染视图的基本方法
    sql注入和暴库
    数据库设计命名规范
    枚举、结构体、联合体的简单应用程序-C语言
  • 原文地址:https://www.cnblogs.com/liuzhaoyzz/p/6198196.html
Copyright © 2011-2022 走看看