VB中实现全局钩子(最好有详细解说 30
PublicConstdwThreadId=0PublicConsthmod=0PublicDeclareFunctionSetWindowsHookExLib"user...
Public Const dwThreadId = 0
Public Const hmod = 0
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
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Const WH_KEYBOARD = 2
Public hHook
Public Function MyKBHook(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If wParam = 123 Then
MsgBox "ok"
End If
End Function
这是我在网上找到的键盘钩子代码(按下F12后会弹出ok),我想将它改成全局的,现在这个代码只有在FORM得到焦点时才能使用,怎样改全局啊。
另外dwThreadId应该怎样才能将它设置为0(我在一些帖子里看到说把它改成0就是全局监控,是真的吗?)
急用,谢谢 展开
Public Const hmod = 0
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
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Const WH_KEYBOARD = 2
Public hHook
Public Function MyKBHook(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If wParam = 123 Then
MsgBox "ok"
End If
End Function
这是我在网上找到的键盘钩子代码(按下F12后会弹出ok),我想将它改成全局的,现在这个代码只有在FORM得到焦点时才能使用,怎样改全局啊。
另外dwThreadId应该怎样才能将它设置为0(我在一些帖子里看到说把它改成0就是全局监控,是真的吗?)
急用,谢谢 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询