赞 | 12 |
VIP | 107 |
好人卡 | 6 |
积分 | 4 |
经验 | 31122 |
最后登录 | 2024-6-29 |
在线时间 | 1606 小时 |
Lv2.观梦者 傻♂逼
- 梦石
- 0
- 星屑
- 374
- 在线时间
- 1606 小时
- 注册时间
- 2007-3-13
- 帖子
- 6562
|
VB版本有,通过api+dll。我希望又能人用ruby使用这个dll(底层Hook)
dll:不猛击的是SB
- Option Explicit
- Private Declare Function StartMaskKey Lib "MaskKey" (lpdwVirtualKey As Long, ByVal nLength As Long, ByVal lpfnKeyboarProc As Long, Optional ByVal bDisableKeyboard As Boolean = False) As Long
- Private Declare Function StopMaskKey Lib "MaskKey" () As Long
-
- Private Sub cmdStartMask_Click()
- ' 屏蔽 A, B, C, 上, 下, 左, 右及两个win键
- Dim key(8) As Long
- key(0) = vbKeyA
- key(1) = vbKeyB
- key(2) = vbKeyC
- key(3) = vbKeyLeft
- key(4) = vbKeyRight
- key(5) = vbKeyUp
- key(6) = vbKeyDown
- key(7) = &H5B ' 左边的win键
- key(8) = &H5C ' 右边的win键
- StartMaskKey key(0), UBound(key) + 1, AddressOf KeyboardProc
- End Sub
-
- Private Sub cmdStopMask_Click()
- StopMaskKey
- End Sub
复制代码- Option Explicit
-
- Private Const WM_KEYDOWN = &H100
- Private Const WM_KEYUP = &H101
- Private Const WM_SYSKEYDOWN = &H104
- Private Const WM_SYSKEYUP = &H105
-
- Public Type KBDLLHOOKSTRUCT
- vkCode As Long ' 虚拟按键码(1--254)
- scanCode As Long ' 硬件按键扫描码
- flags As Long ' flags
- time As Long ' 消息时间戳
- dwExtraInfo As Long ' 额外信息
- End Type
-
- Public Enum KEYACTION
- ACTION_KEYDOWN = WM_KEYDOWN
- ACTION_KEYUP = WM_KEYUP
- ACTION_SYSKEYDOWN = WM_SYSKEYDOWN
- ACTION_SYSKEYUP = WM_SYSKEYUP
- End Enum
-
- ' 全局键盘钩子回调函数
- ' 参数: action 标识键盘消息(按下,弹起), keyStruct 包含按键信息
- Public Function KeyboardProc(ByVal action As KEYACTION, keyStruct As KBDLLHOOKSTRUCT) As Boolean
- Select Case action
- Case ACTION_KEYDOWN
- Debug.Print keyStruct.vkCode, "按下键盘按键"
- Case ACTION_KEYUP
- Debug.Print keyStruct.vkCode, "弹起键盘按键"
- Case ACTION_SYSKEYDOWN
-
- Case ACTION_SYSKEYUP
-
- End Select
-
- ' 返回 True 表示继续传递按键消息
- ' 返回 False 表示结束按键消息传递
- KeyboardProc = False
- End Function
复制代码 系统信息:本贴由楼主认可为正确答案,66RPG感谢您的热情解答~ |
|