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.)
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 unregister call this API:
UnregisterHotKey(IntPtr hwnd, int id);
Both exist in user32
APIs
http://www.pinvoke.net/search.aspx?search=RegisterHotKey&namespace=[All]
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With