views:

49

answers:

3

I have an .net C# winforms application, and I need to add hotkey support, but I want more than the standard RegisterHotKey function, I want be able to support hotkeys like ctrl-ctrl (like in Google Desktop).

Please provide me a direction how to implement this.

edit:

You didn't got it right. I want the hotkey to work even if my application not focused, for example minimized to tray.

A: 

You can get individual keys (like the ctrl key) by polling Console.KeyAvailable and then reading with Console.ReadKey, but that's not going to tell you when they let the key up. You'll probably have to trap the WM_KEYDOWN message and call GetAsyncKeyState at each key so that you can determine which of the special keys (control, shift, alt, etc.) are currently down.

At least, that's what I remember doing back when I was writing games.

Jim Mischel
A: 

If you are using winforms and c# you might be better using keydown or keypress events. And recording previous key presses in a module level variable on the form. Then when the user presses ctl a keypress event will fire, you then look at previous value of keypress and if that was also ctl then you have found the key combination you're looking for.

MikeG
A: 

You would probably have to install a keyboard hook. Now that .NET 4.0 supports loading multiple versions of the CLR into a single process, this is less bad than it once was, but still frowned upon.

Ben Voigt
Keyboard hook is excellent, until it comes to anti-viruses and security products that detects my program as a keylogger :-(
DxCK