Attribute VB_Name = "modDisableLowLevelKeys"
OPTION EXPLICIT
Public DECLARE SUB CopyMemory LIB "kernel32" ALIAS "RtlMoveMemory" (Destination AS ANY, Source AS ANY, BYVAL Length AS LONG)
Public DECLARE FUNCTION GetKeyState LIB "user32" (BYVAL nVirtKey AS LONG) AS INTEGER
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 CallNextHookEx LIB "user32" (BYVAL hHook AS LONG, BYVAL nCode AS LONG, BYVAL wParam AS LONG, lParam AS ANY) AS LONG
Public DECLARE FUNCTION UnhookWindowsHookEx LIB "user32" (BYVAL hHook AS LONG) AS LONG
Public CONST HC_ACTION = 0
Public CONST WM_KEYDOWN = &H100
Public CONST WM_KEYUP = &H101
Public CONST WM_SYSKEYDOWN = &H104
Public CONST WM_SYSKEYUP = &H105
Public CONST VK_TAB = &H9
Public CONST VK_CONTROL = &H11
Public CONST VK_ESCAPE = &H1B
Public CONST WH_KEYBOARD_LL = 13
Public CONST LLKHF_ALTDOWN = &H20
Public TYPE KBDLLHOOKSTRUCT
vkCode AS LONG
scanCode AS LONG
flags AS LONG
time AS LONG
dwExtraInfo AS LONG
END TYPE
DIM p AS KBDLLHOOKSTRUCT
Public FUNCTION LowLevelKeyboardProc(BYVAL nCode AS LONG, BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
DIM fEatKeystroke AS Boolean
IF (nCode = HC_ACTION) THEN
IF wParam = WM_KEYDOWN OR wParam = WM_SYSKEYDOWN OR wParam = WM_KEYUP OR wParam = WM_SYSKEYUP THEN
CopyMemory p, BYVAL lParam, LEN(p)
fEatKeystroke = _
((p.vkCode = VK_TAB) AND ((p.flags AND LLKHF_ALTDOWN) <> 0)) OR _
((p.vkCode = VK_ESCAPE) AND ((p.flags AND LLKHF_ALTDOWN) <> 0)) OR _
((p.vkCode = VK_ESCAPE) AND ((GetKeyState(VK_CONTROL) AND &H8000) <> 0))
END IF
END IF
IF fEatKeystroke THEN
LowLevelKeyboardProc = -1
ELSE
LowLevelKeyboardProc = CallNextHookEx(0, nCode, wParam, BYVAL lParam)
END IF
END FUNCTION
|