tags:

views:

4223

answers:

4

Hi all I'd like to have multiple global hotkeys in my new app (to control the app from anywhere in windows), and all of the given sources/solutions I found on the web seem to provide with a sort of a limping solution (either solutions only for one g.hotkey, or solutions that while running create annoying mouse delays on the screen).

Does anyone here know of a resource that can help me achive this, that I can learn from? Anything?

Thanks ! :)

+6  A: 

http://www.codeproject.com/KB/cs/CSLLKeyboardHook.aspx

If you're not using .net 3.5.

arul
+2  A: 

I would handle this by using P/Invoke to call RegisterHotKey() for each hotkey, and then use NativeForm (assuming you are using WinForms) to be notified of the WM_HOTKEY message. This should keep most of your hotkey code in one place.

Andy
Could you make a quick example of that?
Svish
Are you using WinForms or WPF?
Andy
+2  A: 

The nicest solution I've found is http://bloggablea.wordpress.com/2007/05/01/global-hotkeys-with-net/

Hotkey hk = new Hotkey();

hk.KeyCode = Keys.1;
hk.Windows = true;
hk.Pressed += delegate { Console.WriteLine(“Windows+1 pressed!”); };

hk.Register(myForm); 

Note how you can set different lambdas to different hotkeys

ohadsc