zoukankan      html  css  js  c++  java
  • [VB]全局钩子


    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

  • 相关阅读:
    js中盒子模型常用的属性你还记得几个?
    编写一个关于浏览器盒子模型的方法
    Javascript中关于作用域和闭包和域解释的面试题
    时间格式转换
    HDU Subset sequence
    bugku never give up
    HDU 2136 Largest prime factor
    HDU 2099 整除的尾数
    杭电acm 2070
    ACM Elevator
  • 原文地址:https://www.cnblogs.com/fjfjfjfjfjfj/p/1858372.html
Copyright © 2011-2022 走看看