A small C# (.NET) Library which allows binding of global HotKeys to any Application's Windows (including Windows Apps such as explorer.exe
), even in Background. (using P/Invokes)
Install from NuGet
Install-Package GlobalHotkeys
(or download the Library (.dll) manually)
Example (C#, in a WPF Application):
using mrousavy;
// ...
var key = new HotKey(
(ModifierKeys.Control | ModifierKeys.Alt),
Key.S,
this,
(hotkey) => {
MessageBox.Show("Ctrl + Alt + S was pressed!");
}
);
// ...
key.Dispose();
Note #1: Since
HotKey
implements theIDisposable
interface, you must callDispose()
to unregister the Hotkey, e.g. when your Window closes. Keep in mind that when you're usingusing(...) { ... }
, the HotKey gets unregistered and disposed once you exit the using-statement's scope.
Note #2: Use the binary or operator (
|
) to combine key combinations for the constructor.
Note #3: Use a Window Reference as the third Argument. This may be a WPF
Window
, aWindowInteropHelper
, or a Window Handle (IntPtr
). So you can use your own WPF/WinForms Window, as well as another process's Window using it's Handle. Keep in mind that this is sketchy behaviour and not the intention of this library.