以下内容只是作为实验用:
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
这个哪里错了???只要鼠标移动一下都会有记录出现,退出会出错啊