KBDLLHOOKSTRUCT structure (Windows)

Switch View :
ScriptFree
KBDLLHOOKSTRUCT structure

Applies to: desktop apps only

Contains information about a low-level keyboard input event.

Syntax

typedef struct tagKBDLLHOOKSTRUCT {
  DWORD     vkCode;
  DWORD     scanCode;
  DWORD     flags;
  DWORD     time;
  ULONG_PTR dwExtraInfo;
} KBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT, *LPKBDLLHOOKSTRUCT;

Members

vkCode

Type: DWORD

A virtual-key code. The code must be a value in the range 1 to 254.

scanCode

Type: DWORD

A hardware scan code for the key.

flags

Type: DWORD

The extended-key flag, event-injected flag, context code, and transition-state flag. This member is specified as follows. An application can use the following values to test the keystroke flags.

ValueMeaning
LLKHF_EXTENDED
(KF_EXTENDED >> 8)

Test the extended-key flag.

LLKHF_INJECTED
0x00000010

Test the event-injected flag.

LLKHF_ALTDOWN
(KF_ALTDOWN >> 8)

Test the context code.

LLKHF_UP
(KF_UP >> 8)

Test the transition-state flag.

 

The following table describes the layout of this value.

BitsDescription
0Specifies whether the key is an extended key, such as a function key or a key on the numeric keypad. The value is 1 if the key is an extended key; otherwise, it is 0.
1-3Reserved.
4Specifies whether the event was injected. The value is 1 if the event was injected; otherwise, it is 0.
5The context code. The value is 1 if the ALT key is pressed; otherwise, it is 0.
6Reserved.
7The transition state. The value is 0 if the key is pressed and 1 if it is being released.

 

time

Type: DWORD

The time stamp for this message, equivalent to what GetMessageTime would return for this message.

dwExtraInfo

Type: ULONG_PTR

Additional information associated with the message.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

See also

Reference
LowLevelKeyboardProc
SetWindowsHookEx
Conceptual
Hooks

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Community Content

Thay Singh
KBDLLHOOKSTRUCT.time field is useless
The time field of the KBDLLHOOKSTRUCT is clearly not calibrated in milliseconds as is implied by the documentation's reference to GetMessageTime(). Typing keys at 1-second intervals is giving time field deltas (between one event and its immediate successor in the order as delivered by the hook) that monotonically increase up to 10000 or so and then wrap around to sub-100. And having the system time wrap millis is not an issue in this. $0$0 $0 $0As it stands, the KBDLLHOOKSTRUCT.time field is useless except as a way to totally order the keystrokes. If this is intended behavior, it needs to be documented, otherwise it needs to be fixed.$0 $0

David_González
Declaracion C#
[StructLayout(LayoutKind.Sequential)] 
publicstructKBDLLHOOKSTRUCT
{
    ///<summary>
    /// Especifica el codigo de tecla virtual, el codigo esta entre 1 y 254.
    ///</summary>
    publicint vkCode; 
    ///<summary>
    /// Especifica el escaneo de hardware del codigo de la tecla
    ///</summary>
    publicint scanCode; 
    ///<summary>
    /// especifica flags extendidos, mirar la estrucutra 'KBDLLHOOKSTRUCT' para mas info
    ///</summary>
    publicint flags; 
    ///<summary>
    /// especifica el time stamp para este mensaje.
    ///</summary>
    publicint time; 
    ///<summary>
    /// Especifica informacion extra para el mensaje
    ///</summary>
    publicint dwExtraInfo; 
};




Đonny
Visual Basic 9 declaration
<StructLayout(LayoutKind.Sequential)> _
Public Structure KBDLLHOOKSTRUCT
Public vkCode As Integer
Public scanCode As Integer
Public flags As KBDLLHOOKSTRUCTFlags
Public time As Integer
Public dwExtraInfo As IntPtr
End Structure

<Flags()> _
Public Enum KBDLLHOOKSTRUCTFlags As Integer
LLKHF_EXTENDED = &H1
LLKHF_INJECTED = &H10
LLKHF_ALTDOWN = &H20
LLKHF_UP = &H80
End Enum