请选择 进入手机版 | 继续访问电脑版

玩酷之家

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1127|回复: 0

设置CapsLock、ScrollLock、NumLock键状态

[复制链接]

92

主题

97

帖子

361

积分

中级会员

Rank: 3Rank: 3

积分
361
发表于 2017-11-28 09:10:29 | 显示全部楼层 |阅读模式
本帖最后由 vb6 于 2017-12-10 12:00 编辑

设置CapsLock、ScrollLock、NumLock 按键状态:

  1. Option Explicit
  2. Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
  3. Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
  4. Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long

  5. Const KEYEVENTF_EXTENDEDKEY = &H1
  6. Const KEYEVENTF_KEYUP = &H2

  7. Public Sub SetNumLock(ByVal bLock As Boolean)
  8. Dim i As Boolean, ScanCode As Long
  9. i = CBool(GetKeyState(vbKeyNumlock) And vbShiftMask)
  10. If i <> bLock Then
  11.    ScanCode = MapVirtualKey(vbKeyNumlock, 0)
  12.    Call keybd_event(vbKeyNumlock, ScanCode, 0, 0)
  13.    Call keybd_event(vbKeyNumlock, ScanCode, KEYEVENTF_KEYUP, 0)
  14. End If
  15. End Sub
  16. Public Sub SetScrollLock(ByVal bLock As Boolean)
  17. Dim i As Boolean, ScanCode As Long
  18. i = CBool(GetKeyState(vbKeyScrollLock) And vbShiftMask)
  19. If i <> bLock Then
  20.    ScanCode = MapVirtualKey(vbKeyScrollLock, 0)
  21.    Call keybd_event(vbKeyScrollLock, ScanCode, 0, 0)
  22.    Call keybd_event(vbKeyScrollLock, ScanCode, KEYEVENTF_KEYUP, 0)
  23. End If
  24. End Sub
  25. Public Sub SetCapsLock(ByVal bLock As Boolean)
  26. Dim i As Boolean, ScanCode As Long
  27. i = CBool(GetKeyState(vbKeyCapital) And vbShiftMask)
  28. If i <> bLock Then
  29.    ScanCode = MapVirtualKey(vbKeyCapital, 0)
  30.    Call keybd_event(vbKeyCapital, ScanCode, 0, 0)
  31.    Call keybd_event(vbKeyCapital, ScanCode, KEYEVENTF_KEYUP, 0)
  32. End If
  33. End Sub

  34. Private Sub Command1_Click()
  35. Call SetNumLock(True)

  36. End Sub
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|玩酷之家 ( 鄂ICP备14012049号-1 )

GMT+8, 2018-12-12 15:21 , Processed in 0.157576 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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