Notice Of Closure

Please note that this website is due to close down on 15th June 2020.

In the interim I will try to move as much content as possible over to my GitHub account. Thanks to everyone who has supported the site over the years.

» Help

How to register a global hotkey


Global hotkeys are very handy when your application should be accessible at all time. For instance, you are browsing the Web and suddenly want to e-mail your friend. The most convenient way to do so would be to press a shortcut and the e-mail client would popup with a "new message" window no matter what program you are using at the time. This can be done with global shortcuts. They are system-wide no matter if the program you are using uses the same shortcut. A global shortcut is more important.

Here's the code to register and unregister a global shortcut.

  Messages, Windows;
  // Your main form's class
    procedure WMHotKey(var Message: TMessage); message WM_HOTKEY;
procedure TMainForm.WMHotKey(var Message: TMessage);
  // This example brings the application up front. Put your code here

Example of use:

RegisterHotKey(Handle, 100000 { Any unused number}, MOD_CONTROL, VK_F7);
// When closing program
UnregisterHotKey(Handle, 100000);
Author: Unknown
Added: 2007-06-02
Last updated: 2007-06-02

« Return to contents »