https://github.com/mrousavy/hotkeys
:abc: 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)
https://github.com/mrousavy/hotkeys
bindings dotnet global-hotkeys hotkeys key library windows
Last synced: 2 months ago
JSON representation
:abc: 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)
- Host: GitHub
- URL: https://github.com/mrousavy/hotkeys
- Owner: mrousavy
- License: mit
- Created: 2017-01-10T16:57:37.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-07-30T11:21:21.000Z (almost 5 years ago)
- Last Synced: 2025-03-21T16:21:18.539Z (3 months ago)
- Topics: bindings, dotnet, global-hotkeys, hotkeys, key, library, windows
- Language: C#
- Homepage:
- Size: 2.45 MB
- Stars: 86
- Watchers: 4
- Forks: 13
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
#
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](https://www.nuget.org/packages/GlobalHotkeys)
```
Install-Package GlobalHotkeys
```
[](https://www.nuget.org/packages/GlobalHotkeys/)> _(or [download the Library (.dll)](https://raw.githubusercontent.com/mrousavy/Hotkeys/master/Downloads/Hotkeys.dll) manually)_
# Usage
Example _(C#, in a WPF Application)_:
```cs
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](https://docs.microsoft.com/en-us/dotnet/api/system.idisposable?view=netcore-3.1), 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`](https://docs.microsoft.com/en-us/dotnet/api/system.windows.window?view=netcore-3.1), a [`WindowInteropHelper`](https://docs.microsoft.com/en-us/dotnet/api/system.windows.interop.windowinterophelper?view=netcore-3.1), or a Window Handle ([`IntPtr`](https://stackoverflow.com/questions/1953582/how-to-i-get-the-window-handle-by-giving-the-process-name-that-is-running)). 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.