Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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 days 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 (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-07-30T11:21:21.000Z (over 4 years ago)
- Last Synced: 2024-08-11T00:48:23.142Z (3 months ago)
- Topics: bindings, dotnet, global-hotkeys, hotkeys, key, library, windows
- Language: C#
- Homepage:
- Size: 2.45 MB
- Stars: 79
- Watchers: 5
- 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
```
[![NuGet](https://img.shields.io/nuget/dt/GlobalHotkeys.svg)](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.