Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

Setting up application wide hot key (keyboard short cut)

By Zarko Gajic, About.com

Here's how to code application wide hot-key (keyboard short cut) in a Delphi application. Application wide refers to being able to process keystrokes before they enter the standard keystroke processing.

The following example catches the CTRL + SHIFT + F9 key combination no matter what form (and control on the form) is active.

Note: you need to place a TApplicationEvents ("ApplicationEvents1") component from the Additional palette on a form ("Form1"), then handle the OnShortCut event as in:

~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.ApplicationEvents1ShortCut(var Msg: TWMKey; var Handled: Boolean) ;
begin
   if (Msg.CharCode = VK_F9) and
      (GetKeyState(VK_SHIFT) < 0) and
      (GetKeyState(VK_CONTROL) < 0) then
   begin
     ShowMessage('CTRL + SHIFT + F9 pressed!') ;
     Handled := True;
   end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~
More info:
Virtual Key Codes
How to set system wide Hot Key for a Delphi application
The state of the Shift, Ctrl, Alt keys

Delphi tips navigator:
» Extracting the domain (host) name from an e-mail address
« LastPos function - last occurrence of one string within another

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming

About.com Special Features

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2004 Delphi Tips
  7. Setting up application wide hot key (keyboard short cut)

©2009 About.com, a part of The New York Times Company.

All rights reserved.