Click here to Skip to main content
15,889,462 members
Articles / Programming Languages / C#
Article

System Hotkey Component

Rate me:
Please Sign up or sign in to vote.
4.64/5 (27 votes)
16 Oct 2002 188.2K   3.1K   71   33
handling a System-wide Hotkey

Introduction

SystemHotkey is a simple component providing a wrapper for RegisterHotkey / UnregisterHotkey Win32-Api functions. The component creates a window which listen for WM_HOTKEY messages.

This shows the code inserted by Windows Forms Designer:

C#
private void InitializeComponent()
{
    this.components = new System.ComponentModel.Container();
    this.systemHotkey1 = new CodeProject.SystemHotkey.SystemHotkey(
           this.components);
    this.label1 = new System.Windows.Forms.Label();
    this.label2 = new System.Windows.Forms.Label();
    this.SuspendLayout();
    // 
    // systemHotkey1
    // 
    this.systemHotkey1.Shortcut = System.Windows.Forms.Shortcut.AltF6;
    this.systemHotkey1.Pressed += new System.EventHandler(
           this.systemHotkey1_Pressed);

The Shortcut property sets the Hotkey and activates it. When the Hotkey is pressed the Pressed event is fired. The Hotkey is automaticaly unregistered at Dispose()

You can use this Component with a Tray-Application which activates when a Hotkey is pressed. The files Systemhotkey.cs and win32.cs should be included in a class-library

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionDoes not work with Win98? Pin
slope_cp11-Nov-03 13:30
slope_cp11-Nov-03 13:30 
AnswerRe: Does not work with Win98? Pin
Alexander Werner11-Nov-03 22:52
Alexander Werner11-Nov-03 22:52 
GeneralShortcut vs. Keys Pin
WilcoB17-Oct-02 13:51
sussWilcoB17-Oct-02 13:51 
GeneralRe: Shortcut vs. Keys Pin
Carter Smith25-Feb-03 10:14
Carter Smith25-Feb-03 10:14 
GeneralRe: Shortcut vs. Keys Pin
tayspen2-Jan-06 8:27
tayspen2-Jan-06 8:27 
GeneralRe: Shortcut vs. Keys Pin
michael_ro200017-Oct-06 22:46
michael_ro200017-Oct-06 22:46 
GeneralCould you... Pin
Marc Clifton17-Oct-02 1:57
mvaMarc Clifton17-Oct-02 1:57 
GeneralRe: Could you... Pin
Alexander Werner17-Oct-02 3:09
Alexander Werner17-Oct-02 3:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.