private IntPtr HwndHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            const int WM_HOTKEY = 0x0312;

            if (msg == WM_HOTKEY)
            {
                int id     = wParam.ToInt32();
                var hotkey = _registeredHotkeys.FirstOrDefault(x => x.Id == id);

                if (hotkey != null)
                {
                    if (_requireActiveEveClient && !_windowHelper.IsEveClientActive())
                    {
                        handled = false;
                    }
                    else
                    {
                        var keyEventArgs = new HotkeyEventArgs(hotkey.Gesture);
                        HotkeyPressed?.Invoke(this, keyEventArgs);
                        handled = keyEventArgs.Handled;
                    }

                    if (!handled)
                    {
                        HotkeyNativeMethods.UnregisterHotKey(_handle, hotkey.Id);
                        KeyboardMessage.Send(hotkey.Gesture);
                        HotkeyNativeMethods.RegisterHotKey(_handle, hotkey.Id, hotkey.Modifiers, hotkey.VirtualKey);
                    }
                }
            }

            return(IntPtr.Zero);
        }
        public void UnregisterHotkey(KeyGesture gesture)
        {
            var hotkey = _registeredHotkeys.FirstOrDefault(x => x.Gesture == gesture);

            if (hotkey == null)
            {
                throw new ArgumentException("Hotkey not registered.");
            }

            HotkeyNativeMethods.UnregisterHotKey(_handle, hotkey.Id);

            _registeredHotkeys.Remove(hotkey);
        }
        public bool RegisterHotkey(KeyGesture gesture)
        {
            if (_registeredHotkeys.Any(x => x.Gesture == gesture))
            {
                throw new ArgumentException("Hotkey already registered.");
            }

            var  vk          = KeyInterop.VirtualKeyFromKey(gesture.Key);
            int  id          = GetNextId();
            uint fsModifiers = 0;

            if ((gesture.Modifiers & ModifierKeys.Alt) == ModifierKeys.Alt)
            {
                fsModifiers |= HotkeyNativeMethods.MOD_ALT;
            }

            if ((gesture.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
            {
                fsModifiers |= HotkeyNativeMethods.MOD_CONTROL;
            }

            if ((gesture.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
            {
                fsModifiers |= HotkeyNativeMethods.MOD_SHIFT;
            }

            var result = HotkeyNativeMethods.RegisterHotKey(_handle, id, fsModifiers, (uint)vk);

            if (result)
            {
                _registeredHotkeys.Add(new RegisteredHotKey {
                    Id = id, Gesture = gesture, Modifiers = fsModifiers, VirtualKey = (uint)vk
                });
            }

            return(result);
        }