Tool for registering hot keys
NuGet Package: Resolve.HotKeys
-
Import the namespace
using Resolve.HotKeys;
-
Declare the variable
HotKey xHotKey;
-
Create instance, add event handler and register
try { xHotKey = new HotKey(Keys.X); xHotKey.Pressed += XHotKey_Pressed; xHotKey.Register(); } catch (Exception ex) { Console.WriteLine(ex); }
-
Handle the event
private void XHotKey_Pressed(object sender, EventArgs e) { Console.WriteLine("X pressed."); }
-
Dispose
xHotKey.Pressed -= XHotKey_Pressed; xHotKey.Dispose();