Home

Awesome

<img src="https://github.com/mrousavy/Hotkeys/blob/master/Images/Logo.png?raw=true" width="42"> Hotkeys

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

Install from NuGet

Install-Package GlobalHotkeys

NuGet

(or download the Library (.dll) manually)

<a href='https://ko-fi.com/F1F8CLXG' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://az743702.vo.msecnd.net/cdn/kofi2.png?v=0' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>

Usage

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 the IDisposable interface, you must call Dispose() to unregister the Hotkey, e.g. when your Window closes. Keep in mind that when you're using using(...) { ... }, 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, a WindowInteropHelper, 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.