0

Possible Duplicate:
Register more than one hotkey with RegisterHotKey

Sorry, but I really googled for it a long time and I didn't get any clear code!

I want to know how to register global hot-keys in C# using this:

Win32.RegisterHotKey(hWndSource.Handle, add, 
                     Win32.MOD_CONTROL | Win32.MOD_SHIFT, Win32.VK_KEY_D);

And the most important thing is how to capture multiple hot-keys.

Lets say i want Ctrl+E key strokes to do something different to what Ctrl+R should do.

Community
  • 1
  • 1
blackgh
  • 99
  • 1
  • 13

1 Answers1

0

Check out my rather aged but (I believe) still working solution using Keyboard Hooks, allowing you to create a hook, assign a keyboard shortcut, and capture it as a standard .NET event:

hook = new KeyboardHook();
hook.AddFilter(Keys.E, true /* Ctrl */, false /* Alt */, false /* Shift */);
hook.KeyPressed +=new KeyboardHookEventHandler(hook_KeyPressed);
hook.Install();

(the use of three boolean parameters is far from elegant, and I would have done it with a Flags enum today. My apologies)

Source is here: http://weblogs.asp.net/avnerk/archive/2005/10/06/by-hook-or-by-crook.aspx

Avner Shahar-Kashtan
  • 13,736
  • 3
  • 33
  • 59