⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apikbdllhookstruct.cls

📁 几个不错的VB例子
💻 CLS
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "ApiKBDLLHOOKSTRUCT"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

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

Public CreatedOK As Boolean

'\\ Private memory handling functions
Private Declare Sub CopyMemoryKbdLLHookStruct Lib "KERNEL32" Alias "RtlMoveMemory" (Destination As KBDLLHOOKSTRUCT, ByVal Source As Long, ByVal Length As Long)
Private Declare Function IsBadReadPtrKbdLLHookStruct Lib "KERNEL32" Alias "IsBadReadPtr" (ByVal lp As Long, ByVal ucb As Long) As Long
Private Declare Function IsBadWritePtrKbdLLHookStruct Lib "KERNEL32" Alias "IsBadWritePtr" (ByVal lp As Long, ByVal ucb As Long) As Long

Public vkCode As Long
Public scanCode As Long
Private flags As Long
Public time As Long
Public dwExtraInfo As Long

Public Enum enLowLevelKeyboardFlagHelpers
    LLKHF_EXTENDED = &H1
    LLKHF_INJECTED = &H10
    LLKHF_ALTDOWN = &H20
    LLKHF_UP = &H80
End Enum

'\\ Additional functionality...
Private Declare Function GetKeyNameText Lib "user32" Alias "GetKeyNameTextA" (ByVal lParam As Long, ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function VkKeyScan Lib "user32" Alias "VkKeyScanA" (ByVal cChar As Byte) As Integer

Public Property Get AltPressed() As Boolean

AltPressed = ((flags And LLKHF_ALTDOWN) = flags)
    
End Property


'\\ --[CreateFromPointer]---------------------------------------------
'\\ Fills this KbdLLHookStruct object from the location poiunted to by
'\\ lpKbdLLHookStruct
'\\ VB.NET Porting note: This function should be replaced with an override
'\\ of the New() for correctness
'\\ ----------------------------------------------------------------------------------------
'\\ (c) 2001 - Merrion Computing.  All rights  to use, reproduce or publish this code reserved
'\\ Please check http://www.merrioncomputing.com for updates.
'\\ ----------------------------------------------------------------------------------------
Friend Function CreateFromPointer(lpKbdLLHookStruct As Long) As Boolean

Dim ftThis As KBDLLHOOKSTRUCT

CreatedOK = False

If Not IsBadReadPtrKbdLLHookStruct(lpKbdLLHookStruct, Len(ftThis)) Then
    Call CopyMemoryKbdLLHookStruct(ftThis, lpKbdLLHookStruct, Len(ftThis))
    If Err.LastDllError = 0 Then
        With ftThis
            vkCode = .vkCode
            scanCode = .scanCode
            flags = .flags
            time = .time
            dwExtraInfo = .dwExtraInfo
        End With
        CreatedOK = True
    Else
        ReportError Err.LastDllError, "ApiKbdLLHookStruct:CreateFromPointer", GetLastSystemError
    End If
End If

CreateFromPointer = CreatedOK

End Function

Public Property Get ExtendedKey() As Boolean

ExtendedKey = ((flags And LLKHF_EXTENDED) = flags)

End Property

Public Property Get Injected() As Boolean

Injected = ((flags And LLKHF_INJECTED) = flags)

End Property


'\\ --[KeyNameText]-------------------------------------------------------------------------
'\\ Returns the name of the given virtual key e.g "Space" for
'\\ the spacebar.
'\\ ----------------------------------------------------------------------------------------
'\\ (c) 2001 - Merrion Computing.  All rights  to use, reproduce or publish this code reserved
'\\ Please check http://www.merrioncomputing.com for updates.
'\\ ----------------------------------------------------------------------------------------
Public Property Get KeyNameText() As String

Dim lRet As Long
Dim lParam As Long
Dim lpBuffer As String

'\\ Preinitialise the return string buffer
lpBuffer = String$(255, 0)

'0-15 blank, 16-23 vkCode, 24 - 31 blank
lParam = APIDispenser.MakeLong(0, scanCode)

lRet = GetKeyNameText(lParam, lpBuffer, Len(lpBuffer))
If Err.LastDllError > 0 Then
    ReportError Err.LastDllError, "ApiKBDLLHOOKSTRUCT:KeyNameText", GetLastSystemError
End If
If lRet > 0 Then
    lpBuffer = Left$(lpBuffer, lRet)
Else
    lpBuffer = ""
End If

KeyNameText = lpBuffer

End Property

Public Property Get KeyReleased() As Boolean

KeyReleased = ((flags And LLKHF_UP) = flags)

End Property


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -