Skip to content
kirmir edited this page Jul 15, 2012 · 4 revisions

GlobalHotKey is a library that provides an easy way to register system-wide hot keys for your application and react on them. Internally it wraps Windows API RegisterHotKey and UnregisterHotKey functions and hides all interaction with them from you.

You can download already compiled assembly from the Downloads page. Alternatively, you can install assembly as NuGet package:

PM> Install-Package GlobalHotKey

Classes description

HotKeyManager class registers and unregisters system-wide hot keys, handles them, and raises event on hot keys pressing. KeyPressedEventArgs class contains information about pressed hot key and keys modifiers.

Usage example

using System.Windows.Input;
using GlobalHotKey;
// ...
hotKeyManager = new HotKeyManager();
hotKeyManager.KeyPressed += HotKeyManagerPressed;
// ...
void HotKeyManagerPressed(object sender, KeyPressedEventArgs e)
{
    MessageBox.Show("Hot key pressed!");
}
// ...
// Register Ctrl+Alt+F5
hotKeyManager.Register(Key.F5, ModifierKeys.Control | ModifierKeys.Alt);
// Unregister Ctrl+Alt+F5
hotKeyManager.Unregister(Key.F5, ModifierKeys.Control | ModifierKeys.Alt);
// ...
hotKeyManager.Dispose();
Clone this wiki locally