views:

1077

answers:

4

I want to create a windows utility application, which can be called anytime from within any other application using a keyboard shortcut, e.g.:

• WIN + T

• CTRL+ T

• ALT + T

• CTRL+ ALT + T

• CTRL+ SHIFT + T

What key combinations can I use and how to setup those in the windows registry?

(If the shortcut is used by an other application, it should of course not work.)

A: 

If your application (or a shortcut to it) is available on your desktop, you can right-click to get the context menu, select Properties, and enter the Shortcut Key there. Simply click in the Shortcut Key text field, and press the desired shortcut key.

I've assigned WIN + C to my calculator, and WIN + V to my volume control.

David
Works for Manual shortcut key assignment
Sung Meister
That's funny. This only seems to work for 'native' applications. As every application I've made in winforms c# don't have that setting in the properties dialog when you right click the file on desktop
baeltazor
+1  A: 

If you need more advanced scenario to what the shell shortcut offer, you should start with reading Win32 Hooks and Hooks Overview.

More specifically, you need to add a WH_KEYBOARD hook using the SetWindowsHookEx function. You also need to unhook through UnhookWindowsHookEx when you are done.

There's an old article from Dino Esposito how to do Windows Hooks in .NET through some Win32 interop.

Franci Penov
Works for Programmatic shortcut key assignment
Sung Meister
+3  A: 

An option for doing that programatically when your application start is calling this Windows API: RegisterHotKey(IntPtr hwnd, int id, int fsModifiers, int vk);

And to unregistere call this API:

UnregisterHotKey(IntPtr hwnd, int id);

Both exist in "user32" APIs

[http://www.pinvoke.net/search.aspx?search=RegisterHotKey&namespace=All

Amr ElGarhy
Works for Programmatic shortcut key assignment
Sung Meister
A: 

I'm afraid this isnt something you can do by simply setting values in the registry, it is as has been indicated in other answers necessary to call some windows API routines to achieve this.

Toby Allen