Refer to some foreign websites, forum code, get the following synthesis, the above environment test through, copyright belongs to the original author.
Add a checkbox named chkdisable.caption= "&disable Alt-tab, Alt-esc, Ctrl-esc,lwin,rwin,win+any"
To a new from named Frmmain.frm in new project Hook_kb_ll.vbp
Add code below:
Option Explicit
Dim HHKLOWLEVELKYBD as Long
Private Sub Chkdisable_click ()
If chkdisable = vbchecked Then
HHKLOWLEVELKYBD = SetWindowsHookEx (Wh_keyboard_ll, AddressOf LowLevelKeyboardProc, app.hinstance, 0)
Else
UnhookWindowsHookEx HHKLOWLEVELKYBD
HHKLOWLEVELKYBD = 0
End If
End Sub
Private Sub form_unload (Cancel as Integer)
If hhklowlevelkybd <> 0 Then UnhookWindowsHookEx hhklowlevelkybd
End Sub
In new module named Moddisablelowlevelkeys.bas
Code below:
Option Explicit
Public Declare Sub copymemory Lib "kernel32" Alias "RtlMoveMemory" (destination as all, Source as any, ByVal Length as Long)
Public Declare function getkeystate Lib "user32" (ByVal Nvirtkey as Long) as Integer
Public Declare Function S Etwindowshookex Lib "user32" Alias "Setwindowshookexa" (ByVal Idhook as Long, ByVal LPFN as Long, ByVal hmod as Long, Byva L 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 Hhoo K as long) as long
Public Const HC_ACTION = 0
Public Const WM_KEYDOWN = &h100
Public Const WM_KEYUP = &h1
Public Const WM_SYSKEYDOWN = &h104
Public Const WM_SYSKEYUP = &h105
Public Const VK_TAB = &h9
P ublic 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)) Or _
((P.vkcode =) or (P.vkcode =) or (P.vkcode = 93)) ' Left and right win and logo keys
End If
End If
If Featkeystroke Then
LowLevelKeyboardProc =-1
Else
LowLevelKeyboardProc = CallNextHookEx (0, Ncode, WParam, ByVal LParam)
End If
End Function