How to register a global hotkey for your application in C#

How to register a global hotkey for your application in C#

Register a hotkey for your application that can be triggered even if your form is minimized and does not have focus. More »

How to download a file in C# (progressbar and download speed)

How to download a file in C# (progressbar and download speed)

Learn how to download files in C# while displaying the percentage and the download speed. More »

UDP hole punching implementation in C#

UDP hole punching implementation in C#

Learn how to implement UDP hole punching so you can make your clients life a lot easier by not forcing them to open ports on their end. More »


How to register a global hotkey for your application in C#

If you are looking for a way to set a global hotkey for your C# application that can be used without your form having focus I have created a decently commentated example for you below that you can use.

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone

31 Responses to How to register a global hotkey for your application in C#

  1. Vimal says:

    How to register hotkey combination like ctrl + A + P

  2. Gab Beaudin says:

    Thanks my friend , it’s working perfectly and directly what i wanted !!!

  3. orecchionebruno says:

    Hello, I’m a novice, I tried your code and I have a question.

    How can I grab “CTRL + A + A”?

    I’ll be happy to waiti for your help!

  4. VX7 says:

    Hi, Coolmine, this program raise an exception for me saying that, unable to find an entry point named RegisterHotkey in dll user32.dll what should I do ?

  5. Ahmad says:

    hey nice code but i have a problem . What if i want to register 2 modifiers and a hot key ? example (alt+ shift + a) .
    Any Solution please ?

  6. JBerman says:

    Thank you for the post, it helped to make my hot keys work.

  7. Ruben Vuittonet says:

    This also did not work for me in Windows 10.

    • CooLMinE says:

      I’ve tested the above code on Windows 10 v1709 and it works just fine. If you are having issues I suggest sharing your project so people can take a look.

  8. prasaath says:

    Not working when the application is not activated (out of focus). how to solve the issue?

  9. Abdul Qadir Kapadia says:

    I have one issue:

    Thanks for this superb post, I tried this it works with windows server 2008 but when I run that program in windows 7 it’s getting in indefinite loop.

    Please help !!!

  10. Kay Lee says:

    Hello, found interesting and trying this also able to apply to WPF ?
    I’m writing a WPF application..It’s great but hope also available to WPF !

  11. Michael S Cowan says:

    This does not seem to work in Windows 10 .. IS 0x0312 still the valid message code for hotkey?

    • CooLMinE says:

      Yes, it’s still valid.

      I’ve tried it myself just to make sure since I’m running Windows 10 as well. Seems to be working as expected.

  12. z says:

    Really useful! Thanks a lot!

  13. Delores says:

    Hello this is somewhat of off topic but I was wanting to know if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding experience so I wanted to get advice from someone with experience. Any help would be enormously appreciated!

  14. Excel Developer says:

    Thanks, helped me to register a hotkey for an Excel 2013 Application level add-in (since there is no built event to do this as far as I know so have to listen to the messages). Only needed to change hWnd to:

    RegisterHotKey(new IntPtr(Globals.ThisAddIn.Application.Hwnd), …

    Word of advice though for Excel developers, the handle is different for every workbook you open (not the same as Excel 2010), so on your workbook activate event you need to load that workbooks handle.

  15. Ralph Freshour says:

    I’m new to C# coding. How do I create this app? I created an empty project in my VS 2013 C# IDE but there is no form to paste your code into. I don’t know what kind of form to create.

    I created a new project, WinForm, but that code looks so different from your code I don’t know what kind of structure you are using…WinForm? WPF?

    I need this capability in my C# WinForm but I have no idea how to get your code into my code to make it work.

  16. cosmickinect says:

    Had to personally thank you for this article, it saved me soo much trouble :) thanks!

  17. joe black says:

    Nice post, I use a different method to check the hotkey if you register multiple.
    In your above code I would check the hotkey ID when the message is received like this:

  18. Athena says:

    Hey there! I just wish to give you a huge thumbs up for the excellent information you have right here on this post. I am returning to your blog for more soon.

  19. Ronnie J. says:

    Hello would you mind letting me know which hosting company you’re using? I’ve loaded your blog in 3 different browsers and I must say this blog loads a lot faster then most. Can you suggest a good hosting provider at a fair price? Thank you, I appreciate it!

  20. Willian says:

    Good day I am so happy I found your web site, I really found you by accident, while I was searching on Yahoo for something else, Nonetheless I am here now and would just like to say kudos for a marvelous post and a all round thrilling blog (I also love the theme/design), I don’t have time to read through it all at the moment but I have book-marked it and also added your RSS feeds, so when I have time I will be back to read more, Please do keep up the awesome jo.

  21. Walter says:

    I’ve been surfing online more than 2 hours today, yet I never found any interesting article like yours. It’s pretty worth enough for me. In my view, if all website owners and bloggers made good content as you did, the web will be a lot more useful than ever before.

  22. Katrina says:

    I’m really enjoying the design and layout of your blog. It’s a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hire out a designer to create your theme? Excellent work!

  23. Lenora says:

    I’m not that much of a internet reader to be honest but your sites really nice, keep it up! I’ll go ahead and bookmark your website to come back later on. Cheers

  24. Trista says:

    Hello! I want to say that this article is amazing, great written and come with almost all important infos. I’d like to see extra posts like this .

  25. Welker says:

    Very nice post. I just stumbled upon your weblog and wanted to say that I have truly enjoyed browsing your blog posts.
    After all I’ll be subscribing to your rss feed and I hope you write again soon!

Leave a Reply

Your email address will not be published. Required fields are marked *