Register winform app HotKeys - C#
Hotkey is a very useful shortcut for complex application. Sometimes we build application with much feature include in it hence will result of bad experience of end user because the feature dont have the shortcut keys. Here is a sample to add shortcut keys or hotkeys for winform app in C# code. GlobalHotkeys.cs using System; using System.Windows.Forms; using System.Runtime.InteropServices; namespace Hotkeys { public class GlobalHotkey { private int modifier; private int key; private IntPtr hWnd; private int id; public GlobalHotkey(int modifier, Keys key, Form form) { this.modifier = modifier; this.key = (int)key; this.hWnd = form.Handle; id = this.GetHashCode(); } public bool Register() { return RegisterHotKey(hWnd, id, modifier, key); } public bool Unregiser() { return UnregisterHotKey(hWnd, id); }