0
votes

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 get it right. I want the hotkey to work even if my application not focused, for example minimized to tray.

3

3 Answers

0
votes

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.

0
votes

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.

0
votes

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.