永发信息网

vb 全局HOOK代码问题

答案:1  悬赏:40  手机版
解决时间 2021-08-18 18:59
  • 提问者网友:泪痣哥哥
  • 2021-08-17 23:27

以下内容只是作为实验用:

 

Public Declare Function SetWindowsHookEx Lib "user32" _
Alias "SetWindowsHookExA" _
(ByVal idHook As Long, _
ByVal lpfn As Long, _
ByVal hmod As Long, _
ByVal dwThreadId As Long) As Long    'API申明,消息处理勾子(HOOK),是WINDOWS消息处理的一个平台。
Public Declare Function UnhookWindowsHookEx Lib "user32" _
(ByVal hHook As Long) As Long              ''API申明,卸载消息处理勾子(HOOK),是WINDOWS消息处理的一个平台。
Public Declare Function CallNextHookEx Lib "user32" _
(ByVal hHook As Long, _
ByVal nCode As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Public Type KBDLLHOOKSTRUCT

vkcode As Long
flags As Long
End Type

Public Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(pDest As Any, _
pSource As Any, _
ByVal cb As Long)                    'API申明,内存复制
Public Function LowLevelKeyboardProc(ByVal nCode As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long


Dim kbdllhs As KBDLLHOOKSTRUCT
If nCode >= 0 Then
Call CopyMemory(kbdllhs, ByVal lParam, Len(kbdllhs))
If (kbdllhs.flags) Then
'If kbdllhs.vkcode = 9 Then MsgBox ("哈哈")
'vkCode 是虚拟键位码,上网去查吧,组合键的表达也可查到
'End If
Form1.Text1.Text = Form1.Text1.Text & kbdllhs.vkcode
End If
LowLevelKeyboardProc = CallNextHookEx(m_hDllKbdHook, _
nCode, _
wParam, _
lParam)
End If
End Function

 

 

Private Sub Form_Load()
m_hDllKbdHook = SetWindowsHookEx(WH_KEYBOARD_LL, _
AddressOf LowLevelKeyboardProc, _
App.hInstance, _
0&)
End Sub

Private Sub Form_Unload(Cancel As Integer)
UnhookWindowsHookEx m_hDllKbdHook
Set m_hDllKbdHook = Nothing
End Sub

 

 

这个哪里错了???只要鼠标移动一下都会有记录出现,退出会出错啊

最佳答案
  • 五星知识达人网友:山君与见山
  • 2021-08-17 23:47
我以前也用VB做过,不过老死机。听说VB这方面功能不强。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯