在WIN2K中拦截Alt+Tab,Alt+F4,Ctrl+Esc的模块,希望大家喜欢!(忘了是从哪来的,向原作者至歉。)

'*************************************************************************
'**模 块 名:拦截Alt+Tab,Alt+F4,Ctrl+Esc
'**日    期:2004年05月16日
'**描    述:载入时用 Hook(),  卸载时用UnHook()
'*************************************************************************
'在WIN2K中,执行下面的程序中的Hook(),可以拦截Alt+Tab,Alt+F4,Ctrl+Esc

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 Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Private Type PKBDLLHOOKSTRUCT
    vkCode As Long
    scanCode As Long
    flags As Long
    time As Long
    dwExtraInfo As Long
End Type

Private Const HC_ACTION = 0
Private Const WM_KEYDOWN = &H100
Private Const WM_SYSKEYDOWN = &H104
Private Const WM_KEYUP = &H101
Private Const WM_SYSKEYUP = &H105
Private Const VK_TAB = &H9
Private Const VK_ESCAPE = &H1B
Private Const VK_CONTROL = &H11
Private Const WH_KEYBOARD_LL = 13
Private Const LLKHF_ALTDOWN = &H20

Private PrevHook As Long

Public Sub Hook()
    PrevHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.hInstance, 0)
End Sub


Public Sub UnHook()
    UnhookWindowsHookEx PrevHook
End Sub

Public Function LowLevelKeyboardProc(ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim fEatKeystroke As Boolean
    Dim p As PKBDLLHOOKSTRUCT
   
    If ncode = HC_ACTION Then
        Select Case wParam
            Case WM_KEYDOWN, WM_SYSKEYDOWN, WM_KEYUP, WM_SYSKEYUP
                CopyMemory p, ByVal lParam, Len(p)
                If (p.flags And LLKHF_ALTDOWN) <> 0 Then 'Alt + AnyKey
                    fEatKeystroke = True
                End If
                If (p.vkCode = VK_ESCAPE) And ((GetKeyState(VK_CONTROL) And &H8000) <> 0) Then 'Ctrl + Esc
                    fEatKeystroke = True
                End If
            Case Else
                'do nothing
        End Select
    End If
   
    If fEatKeystroke Then
        LowLevelKeyboardProc = 1
    Else
        CallNextHookEx WH_KEYBOARD_LL, ncode, wParam, lParam
    End If
End Function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值