ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 483|回复: 3

[已解决] 如何打开键盘上的大写锁定,SendKeys "{CAPSLOCK}"行不通

[复制链接]

TA的精华主题

TA的得分主题

发表于 2022-12-6 10:02 | 显示全部楼层 |阅读模式
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
本帖最后由 桑特容易额 于 2022-12-7 13:53 编辑

1

2

3

4

5

6

7

8

9

10

11

12

Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Const VK_CAPITAL As Long = &H14
Private Const VK_NUMLOCK As Long = &H90
Private Const VK_SHIFT = &H10

Sub aaa()
If GetKeyState(VK_CAPITAL) Mod &HFF80 = 1 Then
    MsgBox "当前处于大写状态"
Else
    SendKeys "{CAPSLOCK}"
End If
End Sub


TA的精华主题

TA的得分主题

发表于 2022-12-6 21:49 | 显示全部楼层
本帖最后由 smsn 于 2022-12-6 21:54 编辑

image.png

code.zip

361 Bytes, 下载次数: 2

评分

1

查看全部评分

TA的精华主题

TA的得分主题

发表于 2022-12-6 21:53 | 显示全部楼层
  1. #If VBA7 Then
  2.     Declare PtrSafe Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As LongPtr)
  3. #Else
  4.     Declare Sub keybd_event Lib "user32" Alias "keybd_event" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
  5. #End If

  6. Const KEYEVENTF_KEYUP = &H2
  7. Const VK_CAPITAL As Long = &H14

  8. Sub CAP()
  9.     '按下
  10.     keybd_event VK_CAPITAL, 0, 0, 0
  11.     '释放
  12.     keybd_event VK_CAPITAL, 0, KEYEVENTF_KEYUP, 0
  13. End Sub
复制代码


其他按键
  1. Private Const VK_ADD As Long = &H6B          '加号键
  2. Private Const VK_APPS As Long = &H5D         'Applications 键(相当于鼠标右键)
  3. Private Const VK_BACK As Long = &H8          'BackSpace 键
  4. Private Const VK_CAPITAL As Long = &H14      'Caps Lock 键(大小写转换键)
  5. Private Const VK_CANCEL As Long = &H3        'Ctrl + Break 过程
  6. Private Const VK_CONTROL As Long = &H11
  7. Private Const VK_DECIMAL As Long = &H6E      '小数点号键
  8. Private Const VK_DELETE As Long = &H2E
  9. Private Const VK_DIVIDE As Long = &H6F       '除号键
  10. Private Const VK_DOWN As Long = &H28
  11. Private Const VK_END As Long = &H23
  12. Private Const VK_ESCAPE As Long = &H1B
  13. Private Const VK_F1 As Long = &H70
  14. Private Const VK_F10 As Long = &H79
  15. Private Const VK_F11 As Long = &H7A
  16. Private Const VK_F12 As Long = &H7B
  17. Private Const VK_F2 As Long = &H71
  18. Private Const VK_F3 As Long = &H72
  19. Private Const VK_F4 As Long = &H73
  20. Private Const VK_F5 As Long = &H74
  21. Private Const VK_F6 As Long = &H75
  22. Private Const VK_F7 As Long = &H76
  23. Private Const VK_F8 As Long = &H77
  24. Private Const VK_F9 As Long = &H78
  25. Private Const VK_HOME As Long = &H24
  26. Private Const VK_INSERT As Long = &H2D
  27. Private Const VK_LCONTROL As Long = &HA2
  28. Private Const VK_LEFT As Long = &H25
  29. Private Const VK_LMENU As Long = &HA4        '左 Alt 键
  30. Private Const VK_LSHIFT As Long = &HA0
  31. Private Const VK_LWIN As Long = &H5B
  32. Private Const VK_MENU As Long = &H12         'Alt 键
  33. Private Const VK_MULTIPLY As Long = &H6A     '乘号键
  34. Private Const VK_NEXT As Long = &H22         '下翻页键
  35. Private Const VK_NUMLOCK As Long = &H90
  36. Private Const VK_NUMPAD0 As Long = &H60
  37. Private Const VK_NUMPAD1 As Long = &H61
  38. Private Const VK_NUMPAD2 As Long = &H62
  39. Private Const VK_NUMPAD3 As Long = &H63
  40. Private Const VK_NUMPAD4 As Long = &H64
  41. Private Const VK_NUMPAD5 As Long = &H65
  42. Private Const VK_NUMPAD6 As Long = &H66
  43. Private Const VK_NUMPAD7 As Long = &H67
  44. Private Const VK_NUMPAD8 As Long = &H68
  45. Private Const VK_NUMPAD9 As Long = &H69
  46. Private Const VK_PAUSE As Long = &H13
  47. Private Const VK_PRINT As Long = &H2A
  48. Private Const VK_PRIOR As Long = &H21        '上翻页键
  49. Private Const VK_RCONTROL As Long = &HA3
  50. Private Const VK_RETURN As Long = &HD        '回车键
  51. Private Const VK_RIGHT As Long = &H27
  52. Private Const VK_RMENU As Long = &HA5        '右 Alt 键
  53. Private Const VK_RSHIFT As Long = &HA1
  54. Private Const VK_RWIN As Long = &H5C
  55. Private Const VK_SCROLL As Long = &H91       'Scroll Lock 键
  56. Private Const VK_SEPARATOR As Long = &H6C    '小键盘上的回车键
  57. Private Const VK_SHIFT As Long = &H10
  58. Private Const VK_SLEEP As Long = &H5F        '休眠键
  59. Private Const VK_SNAPSHOT As Long = &H2C     'Print Screen 键
  60. Private Const VK_SPACE As Long = &H20
  61. Private Const VK_SUBTRACT As Long = &H6D     '减号键
  62. Private Const VK_TAB As Long = &H9
  63. Private Const VK_UP As Long = &H26
复制代码

TA的精华主题

TA的得分主题

 楼主| 发表于 2022-12-7 09:05 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-20 13:19 , Processed in 0.036243 second(s), 16 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

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