Click here to Skip to main content
13,287,116 members (41,477 online)
Click here to Skip to main content
Add your own
alternative version


54 bookmarked
Posted 9 Aug 2010

Smart Hotkey Handler .NET

, 9 Aug 2010
Rate this:
Please Sign up or sign in to vote.
Tutorial about Smart Hot Key Handler .NET control library


Basically hot keys provide quick access to a feature of software application by pressing finite set of one or more keys. These keys will work even when the specific application is inactive or hidden. Normally implementing hot-keys feature for an application is a complex process. I want to make it simple and it is needed for one of my projects. After spending some time with MSDN, I created the Smart Hot key Handler in C#.NET. It will very useful for .NET based windows application developers; they can use it even they don't have any knowledge on Win32 application and libraries.

Using the Smart Hot Key Handler

Smart Hotkey handler.NET allows Windows applications to subscribe all registered hotkey events with minimum efforts. It supports to register all normal keys and function keys as hot key with or without key modifiers (Alt, Shift, Control and Windows).

You can get the full source code of this handler here.

Follow the steps given below to use the smart hot key handler in a test application.

  1. Create a new Windows Application from Visual Studio 2008.
  2. Add Smart Hot key control to Toolbox (if not available), then drag and drop on to your form.
  3. Open your form code file and add the following line of code at the constructor of the form.
    this.hotKey1.HotKeyPressed += 
    	new SmartHotKey.HotKey.HotKeyEventHandler(hotKey1_HotKeyPressed); 
  4. Add the hot key press event handler.
    void hotKey1_HotKeyPressed(object sender, SmartHotKey.HotKeyEventArgs e)
  5. Register all required hot-keys.
    //normal keys
    //normal keys with keymodifiers
    //function keys
    //function keys with keymodifiers
    //other keys[Home,End,PageDown,PageUp and Delete]
  6. Add the following line of code inside of the Dispose method to release the hot key handler.
    //remove all keys
    //remove the specific hot key
    this.hotKey1.RemoveKey("Shift+End"); //you can call this method 
    				//wherever you want to remove a hotkey.
    		//It will release the hotkey handler from your application.
  7. Now you run and test your application, you can get the following messages when you hit one or more keys on your keyboard.

Sample Outputs






In the same way, you can customize the hot key combination based on your requirements.


I hope this will reduce your development time on hot key implementation for your application. Currently Windows key modifier combination hot-keys are not working properly. If you have any workaround or solution, please share with me.

This is my first article, so I look forward to getting your feedback on grammatical and technical mistakes. It will really help me to improve myself and write more useful articles.


  • 9th August, 2010: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Architect FE
India India
.Net Software Architect,I primarily work on ASP.NET, WPF and WCF. I have good experience on designing robust application. I love listening to music.

You may also be interested in...

Comments and Discussions

QuestionQuick Help guide for this tool Pin
Willy Kimura7-Aug-15 1:38
professionalWilly Kimura7-Aug-15 1:38 
AnswerRe: Quick Help guide for this tool Pin
techbird10-Aug-15 3:34
membertechbird10-Aug-15 3:34 
GeneralRe: Quick Help guide for this tool Pin
Willy Kimura22-Aug-15 11:49
professionalWilly Kimura22-Aug-15 11:49 
Questionvery nice Pin
expert-programmer15-Nov-13 8:57
memberexpert-programmer15-Nov-13 8:57 
Questionhow to use space and arrow key Pin
Hitesh Rohilla23-Jun-13 7:42
professionalHitesh Rohilla23-Jun-13 7:42 
QuestionCan't we ? Pin
Tarek Elqusi7-Jan-13 1:45
memberTarek Elqusi7-Jan-13 1:45 
Can't we capture hot keys without using the Win32 functions ? I just need to capture the ALT+F4 to prevent closing a form and I do not need to include all this stuff
QuestionF12 is not Working Pin
luckyaruns3-Feb-12 4:49
memberluckyaruns3-Feb-12 4:49 
QuestionNOt able to register F12 Pin
luckyaruns24-Jan-12 3:45
memberluckyaruns24-Jan-12 3:45 
GeneralMy vote of 5 Pin
oned218-Oct-10 10:05
memberoned218-Oct-10 10:05 
GeneralNice Pin
Chona117111-Aug-10 23:41
memberChona117111-Aug-10 23:41 
QuestionWindows? Pin
Christ Kennedy10-Aug-10 12:24
memberChrist Kennedy10-Aug-10 12:24 
AnswerRe: Windows? Pin
techbird11-Aug-10 7:49
membertechbird11-Aug-10 7:49 
AnswerRe: Windows? Pin
Chona117111-Aug-10 23:43
memberChona117111-Aug-10 23:43 
AnswerRe: Windows? Pin
techbird12-Aug-10 21:55
membertechbird12-Aug-10 21:55 
GeneralRe: Windows? Pin
Christ Kennedy13-Aug-10 3:54
memberChrist Kennedy13-Aug-10 3:54 
GeneralRe: Windows? Pin
techbird17-Aug-10 7:48
membertechbird17-Aug-10 7:48 
AnswerRe: Windows? Pin
Willy Kimura7-Aug-15 1:05
professionalWilly Kimura7-Aug-15 1:05 
GeneralVery Useful Pin
ScruffyDuck10-Aug-10 11:20
memberScruffyDuck10-Aug-10 11:20 
QuestionWhat's about global hot keys? Pin
tarasn9-Aug-10 22:15
membertarasn9-Aug-10 22:15 
AnswerRe: What's about global hot keys? Pin
techbird10-Aug-10 9:03
membertechbird10-Aug-10 9:03 
GeneralRe: What's about global hot keys? Pin
tarasn10-Aug-10 11:53
membertarasn10-Aug-10 11:53 
GeneralRe: What's about global hot keys? Pin
techbird11-Aug-10 7:51
membertechbird11-Aug-10 7:51 
GeneralBetter as a Tip/Trick or Blog post Pin
digital man8-Aug-10 22:26
memberdigital man8-Aug-10 22:26 
GeneralRe: Better as a Tip/Trick or Blog post Pin
techbird10-Aug-10 8:51
membertechbird10-Aug-10 8:51 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171207.1 | Last Updated 9 Aug 2010
Article Copyright 2010 by techbird
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid