https://github.com/shadowsocks/globalhotkey
Provides an easy way to setup system-wide hot keys and react on their events. Fork here in case something wrong with nuget or upstream repository.
https://github.com/shadowsocks/globalhotkey
Last synced: 5 months ago
JSON representation
Provides an easy way to setup system-wide hot keys and react on their events. Fork here in case something wrong with nuget or upstream repository.
- Host: GitHub
- URL: https://github.com/shadowsocks/globalhotkey
- Owner: shadowsocks
- License: gpl-3.0
- Fork: true (kyrylomyr/GlobalHotKey)
- Created: 2016-12-19T08:24:38.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-10-30T11:00:19.000Z (over 8 years ago)
- Last Synced: 2024-12-08T01:01:04.162Z (6 months ago)
- Language: C#
- Homepage:
- Size: 36.1 KB
- Stars: 7
- Watchers: 7
- Forks: 21
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Global Hot Key
Provides an easy way to setup system-wide hot keys and react on their events. Works well in both, WPF and WebForms applications without any need to use Windows API.[](https://badge.fury.io/nu/GlobalHotKey)
[](https://ci.appveyor.com/project/kirmir/globalhotkey-9re99)# Installation
Th package is available through the NuGet by running the command
```
PM> Install-Package GlobalHotKey
```# Usage
An example below demonstrates how to register system-wide hotkey Ctrl+Alt+F5 and handle it:
```csharp
// Include required namespaces.
using System.Windows.Input;
using GlobalHotKey;// Create the hotkey manager.
hotKeyManager = new HotKeyManager();// Register Ctrl+Alt+F5 hotkey. Save this variable somewhere for the further unregistering.
var hotKey = hotKeyManager.Register(Key.F5, ModifierKeys.Control | ModifierKeys.Alt);// Handle hotkey presses.
hotKeyManager.KeyPressed += HotKeyManagerPressed;private void HotKeyManagerPressed(object sender, KeyPressedEventArgs e)
{
if (e.HotKey.Key == Key.F5)
MessageBox.Show("Hot key pressed!");
}// Unregister Ctrl+Alt+F5 hotkey.
hotKeyManager.Unregister(hotKey);// Dispose the hotkey manager.
hotKeyManager.Dispose();
````HotKeyManager` class registers and unregisters system-wide hotkeys, handles them, and raises an event on hotkeys pressing. `KeyPressedEventArgs` class contains information about pressed hotkey and keys modifiers.
Note, that it is not necessary to unregister all hotkeys manually before closing application, because `Dispose()` does it. Make sure that it is called.