Как только на окне жертвы возникает событие KEYBOARD, вылетает ошибка "Память не может быть read"
- Код: Выделить всё
Private Sub GetOpt(wWnd As Long)
'получить HInstance и ThreadId зная hwnd окна
Dim Ti As Long
Dim Hi As Long
Hi = GetWindowLong(wWnd, GWL_HINSTANCE)
Ti = GetWindowThreadProcessId(wWnd, 0&)
hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, Hi, Ti)
End Sub
- Код: Выделить всё
'In a module
Public Const WH_KEYBOARD = 2
Public Const VK_SHIFT = &H10
Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
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
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public hHook As Long
Public Function KeyboardProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'if idHook is less than zero, no further processing is required
If idHook < 0 Then
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
Else
'check if SHIFT-S is pressed
If (GetKeyState(VK_SHIFT) And &HF0000000) And wParam = Asc("S") Then
'show the result
Form1.Print "Shift-S pressed ..."
End If
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
End If
End Function