VB中的Hook函数里 用什么来判断某个按键的按键情况?
发布网友
发布时间:2023-04-24 02:55
我来回答
共1个回答
热心网友
时间:2023-10-10 23:34
笑了 不知道你怎么验证出来不好了下面就是KB 钩子的回调函数Public Function LowLevelKeyboardProc(ByVal nCode As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Static kbdllhs As KBDLLHOOKSTRUCT 'KB HOOK的结构 自己声明
If nCode = HC_ACTION '有消息需要处理
If wParam = WM_KEYDOWN Then'检测到按键
Call CopyMemory(kbdllhs, ByVal lParam, Len(kbdllhs))'复制内存中的数据
'F1 --------------
If kbdllhs.vkCode = VK_F1 Then'虚拟吗
LowLevelKeyboardProc = 1 '值为 1 表示拦截该信息
Exit Function
End If
End If 'kbdllhs.vkCode = VK_F1
'F2 --------------
If kbdllhs.vkCode = VK_F2 Then
If Form1.Text1(1).Text = "" Then
LowLevelKeyboardProc = 0
Exit Function
Else
LowLevelKeyboardProc = 1
Clipboard.Clear
Clipboard.SetText (Form1.Text1(1).Text)
SendKeys "^(V)"
Exit Function
End If
End If 'kbdllhs.vkCode = VK_F2
'F3 --------------
If kbdllhs.vkCode = VK_F3 Then
If Form1.Text1(2).Text = "" Then
LowLevelKeyboardProc = 0
Exit Function
Else
LowLevelKeyboardProc = 1
Clipboard.Clear
Clipboard.SetText (Form1.Text1(2).Text)
SendKeys "^(V)"
Exit Function
End If
End If 'kbdllhs.vkCode = VK_F3
End If 'wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN
End If 'nCode = HC_ACTION
LowLevelKeyboardProc = CallNextHookEx(m_hDllKbdHook, nCode, wParam, lParam)
End Function