● Greatis ● Security ● AppDatabase ● Utilities ● Android ● .NET ● just4fun
Delphi / C++ Builder
Components, utilities and tips for Delphi and C++ Builder developers
Keyboard Hook
OnKeyboardHook event with raw WinAPI data
Standard VCL's OnKeyDown and OnKeyUp events
Related components
Mouse Hook
Hot Keys

Other Delphi components
.Net components

Free Delphi Software
Omid Motahed's Free Delphi Software
Special offer!
Follow us
LinkedIn Twitter Facebook

Keyboard Hook

System-Wide Keyboard Events Tracking Component for VCL

For all versions of Delphi and C++ Builder from 3 to 10.2 Tokyo and for all versions of Windows from XP to 10

Keyboard Hook component is a system-wide keyboard events tracker that works without external DLL.

TKeyboardHook Interface


procedure KeyboardHookProc(VirtualKeyCode,ScanCode,Flags,Time: Integer; ExtraInfo: Pointer); virtual;
Hook calls this virtual procedure for each keyboard event, you can override it to implement your own keyboard events handlers in derived class.


constructor Create(AOwner: TComponent); override;
Overridden constructor creates object and initializes internal data.

destructor Destroy; override;
Overridden destructor frees internal data and destroys the object.

procedure Start;
Starts hook. You can also activate hook with Active property.

procedure Stop;
Stops hook. You can also deactivate hook with Active property.

property Active: Boolean;
Hook activity state.


property OnKeyboardHook: TKeyboardHookEvent;
This event occurs for each keyboard event and distributes low-level data for keyboard event. TKeyboardHookEvent is declared as

TKeyboardHookEvent = 
  procedure(Sender: TObject;
  VirtualKeyCode,ScanCode,Flags,Time: Integer;
  ExtraInfo: Pointer) of object;
The event parameters contains keyboard message identifier and members of WinAPI's KBDLLHOOKSTRUCT structure.

property OnKeyDown: TKeyEvent;
Occurs when user presses key.

property OnKeyUp: TKeyEvent;
Occurs when user releases key.

property OnChars: TCharsEvent;
Occurs when user presses character key. TCharsEvent is declared as
TCharsEvent = procedure(Sender: TObject; Chars: string) of object;
When user enter dead-key character (accent or diacritic) the output can be more than 1 character.

Keyboard Hook component suite includes demo project that demonstrates main features of TKeyboardHook component:

Keyboard Hook Demo

Download free demo, order full source code right now!

Greatis Software
eXTReMe Tracker