1. Computing

Setting up application wide hot key (keyboard short cut)


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) ;
   if (Msg.CharCode = VK_F9) and
      (GetKeyState(VK_SHIFT) < 0) and
      (GetKeyState(VK_CONTROL) < 0) then
     ShowMessage('CTRL + SHIFT + F9 pressed!') ;
     Handled := True;
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

©2014 About.com. All rights reserved.