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

How to set system wide Hot Key for a Delphi application

By Zarko Gajic, About.com

An answer to the quesion: "My application is minimized in the Tray and I want to know how to code a "short-cut" key, for example Alt-Shift-F9, to bring my application to the top of the Desktop screen?"

~~~~~~~~~~~~~~~~~~~~~~~~~
//In the main forms OnCreate
//handler assign the hotkey:

If not RegisterHotkey
    (Handle, 1, MOD_ALT or MOD_SHIFT, VK_F9) Then
     ShowMessage('Unable to assign Alt-Shift-F9 as hotkey.') ;

//In the main forms
//OnClose event remove the handler:

   UnRegisterHotkey( Handle, 1 ) ;

//Add a handler for the
//WM_HOTKEY message to the form:

   private // form declaration
     Procedure WMHotkey( Var msg: TWMHotkey ) ;
       message WM_HOTKEY;

Procedure TForm1.WMHotkey( Var msg: TWMHotkey ) ;
   Begin
     If msg.hotkey = 1 Then Begin
       If IsIconic( Application.Handle ) Then
         Application.Restore;
       BringToFront;
     End;
   End;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Create an Auto-Run CD
« Implementing Application.Restart

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2001 Delphi Tips
  7. How to set system wide Hot Key for a Delphi application

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

All rights reserved.