Option Explicit
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Private 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
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function FindWindow Lib "user32 " Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Type PKBDLLHOOKSTRUCT
VKCode As Long
scanCode As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type
Private Const WH_KEYBOARD_LL = 13
Private Const HC_ACTION = 0
Private Const WM_KEYDOWN = &H100
Private Const VK_SNAPSHOT = &H2C
Private PrevHook As Long
Public Function LowLevelKeyboardProc(ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If ncode = HC_ACTION Then
If wParam = WM_KEYDOWN Then
Dim p As PKBDLLHOOKSTRUCT
CopyMemory p, ByVal lParam, Len(p)
If p.VKCode = VK_XXX Then ’when XXX Key pressed cancel
LowLevelKeyboardProc = -1
Exit Function
End If
End If
End If
CallNextHookEx WH_KEYBOARD_LL, ncode, wParam, lParam
End Function
Public Sub Hook()
PrevHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.hInstance, 0)
End Sub
Public Sub ReleaseHook()
Call UnhookWindowsHookEx(PrevHook)
End Sub