Click here to Skip to main content
11,631,369 members (73,891 online)
Click here to Skip to main content

System Hotkey Component

, 16 Oct 2002 147.6K 2.6K 69
Rate this:
Please Sign up or sign in to vote.
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:

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

Share

About the Author

Alexander Werner
Web Developer
Germany Germany
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionLicense or Terms Of Use? Pin
ChristopJB14-Oct-08 12:19
memberChristopJB14-Oct-08 12:19 
GeneralDon't power off or restart the PC Pin
kriegsmar1-Jun-07 11:11
memberkriegsmar1-Jun-07 11:11 
QuestionVista bug? Pin
ETL .Net28-Mar-07 14:26
memberETL .Net28-Mar-07 14:26 
QuestionUsing Windows as a modifier key? Pin
Kbirger20-Oct-06 3:17
memberKbirger20-Oct-06 3:17 
GeneralPlease fix multiple Mod key selection Pin
countryBumkin15-Jun-06 9:13
membercountryBumkin15-Jun-06 9:13 
QuestionCan you add event KeyDown and KeyUp Please! Pin
ndphuong4-May-06 1:29
memberndphuong4-May-06 1:29 
AnswerRe: Can you add event KeyDown and KeyUp Please! Pin
Kbirger20-Oct-06 3:15
memberKbirger20-Oct-06 3:15 
Questionwhere are the numbers coming from? Pin
jhazlett8-Mar-06 17:03
memberjhazlett8-Mar-06 17:03 
AnswerRe: where are the numbers coming from? Pin
Alexander Werner8-Mar-06 22:07
memberAlexander Werner8-Mar-06 22:07 
GeneralBinding Hotkey in real time Pin
Markclee3-Nov-05 12:40
memberMarkclee3-Nov-05 12:40 
GeneralRe: Binding Hotkey in real time Pin
Skoobie Du26-Jun-07 2:38
memberSkoobie Du26-Jun-07 2:38 
GeneralDefault functionality of mapped hotkey Pin
makasili27-Oct-05 10:45
membermakasili27-Oct-05 10:45 
GeneralRe: Default functionality of mapped hotkey Pin
Skoobie Du26-Jun-07 2:19
memberSkoobie Du26-Jun-07 2:19 
GeneralOn lost focus - Hotkeys should get unregistered Pin
sona_zar25-Aug-05 1:22
membersona_zar25-Aug-05 1:22 
GeneralRe: On lost focus - Hotkeys should get unregistered Pin
Alexander Werner25-Aug-05 1:47
memberAlexander Werner25-Aug-05 1:47 
GeneralRe: On lost focus - Hotkeys should get unregistered Pin
sona_zar25-Aug-05 3:42
membersona_zar25-Aug-05 3:42 
GeneralRe: On lost focus - Hotkeys should get unregistered Pin
sona_zar25-Aug-05 4:25
membersona_zar25-Aug-05 4:25 
GeneralRe: On lost focus - Hotkeys should get unregistered Pin
Skoobie Du26-Jun-07 1:59
memberSkoobie Du26-Jun-07 1:59 
GeneralRe: On lost focus - Hotkeys should get unregistered Pin
ekb02116-Jul-07 10:52
memberekb02116-Jul-07 10:52 
GeneralUpdate to RegisterHotKey method Pin
Rick Hobbs @ NeoWorks24-Sep-04 0:47
sussRick Hobbs @ NeoWorks24-Sep-04 0:47 
GeneralRe: Update to RegisterHotKey method Pin
timbits21410-Dec-04 19:29
membertimbits21410-Dec-04 19:29 
GeneralRe: Update to RegisterHotKey method Pin
timbits21411-Dec-04 12:13
membertimbits21411-Dec-04 12:13 
GeneralRe: Update to RegisterHotKey method Pin
Xaroth18-May-06 0:22
memberXaroth18-May-06 0:22 
GeneralRe: Update to RegisterHotKey method Pin
countryBumkin15-Jun-06 9:11
membercountryBumkin15-Jun-06 9:11 
GeneralRe: Update to RegisterHotKey method Pin
olveram730-Jun-06 14:36
memberolveram730-Jun-06 14:36 
QuestionDoes not work with Win98? Pin
T. Rumland (tr_cr)11-Nov-03 13:30
sussT. Rumland (tr_cr)11-Nov-03 13:30 
AnswerRe: Does not work with Win98? Pin
Alexander Werner11-Nov-03 22:52
memberAlexander 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
memberCarter Smith25-Feb-03 10:14 
GeneralRe: Shortcut vs. Keys Pin
tayspen2-Jan-06 8:27
membertayspen2-Jan-06 8:27 
GeneralRe: Shortcut vs. Keys Pin
michael_ro200017-Oct-06 22:46
membermichael_ro200017-Oct-06 22:46 
GeneralCould you... Pin
Marc Clifton17-Oct-02 1:57
memberMarc Clifton17-Oct-02 1:57 
GeneralRe: Could you... Pin
Alexander Werner17-Oct-02 3:09
memberAlexander Werner17-Oct-02 3:09 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150723.1 | Last Updated 17 Oct 2002
Article Copyright 2002 by Alexander Werner
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid