Win2KNTXP Environment LWIN, RWIN, WIN + ANY, CTRL + ESC, ALT + ESC, Alt + Tab oriented

xiaoxiao2021-03-06  95

Refer to some websites, forum code, get the following synthesis, the above environment is passed, 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.vbpadd code Below:

Option expedition

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 = 0End IfEnd Sub

Private Sub Form_Unload (Cancel As Integer) if hhklowlevelkybd <> 0 THEN UNHOOKWINDOWSHOKEX HHKLOWLEVELKYBDEND SUB

In New Module Named ModdisablelowlevelKeys.bascode Below: 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 IntegerPublic Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As LongPublic Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As LongPublic Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As LongPublic Const HC_ACTION = 0Public Const WM_KEYDOWN = & H100Public Const WM_KEYUP = & H101Public Const WM_SYSKEYDOWN = & H104Public Const WM_SYSKEYUP = & H105Public Const VK_TAB = & H9Public Const VK_CONTROL = & H11Public Const VK_ESCAPE = & H1B

Public const wh_keyboard_ll = 13public constlkhf_altdown = & h20public Type KBDLLHOOKSTRUCT VKCODE AS Long Scancode As Long Flags As Long Time As Long Dwextrainfo As Longend Type

DIM P as kbdllhookingtruct

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.flags and llkhf_altdown <> 0) or _ (p.vkcode = vk_escape) and ((GetKeyState (VK_Control) and & h8000) <> 0)) or _ ( (p.vkcode = 91) or (p.vkcode = 92) or (p.vkcode = 93)) 'Tab Alt' ESC Alt 'Alt ANY (Alt F4)' ESC Ctrl 'left and right WIN and logo Key end if end if if featkeystroc = -1 else loWevelKeyboardProc = CallNexthookex (0, Ncode, WPARAM, BYVAL LPARAM) End IFend FUNCTION

Supplement reference more:

Http://www.vbnet.mvps.org/index.html?code/hook/lowlevelkeyboardproc.htmhtp://www.zjol.com.cn/vbbible/software/program/vb/ccw/main.htm#hook

转载请注明原文地址:https://www.9cbs.com/read-123437.html

New Post(0)