JG Vimalan's Blog

It is all about coding!

Handling hotkeys in Windows Forms application

There may be situations where you want to launch your windows application using an hotkey. I assume that, you have already set hot key for your windows application. So, in the form, all you need to do is, override the WndProc method as shown below,

namespace hkWin
    public partial class Main : Form

 protected override void WndProc(ref Message m)
            if (m.Msg == 786)
                //place your code here
            base.WndProc(ref m);

the number 786 will confirm whether the keys hit in keyboard is the hotkey for this application. This method will fireup even if the form is not in focus/minimized.

November 10, 2010 - Posted by | C#.NET, Windows Forms

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: