babalae/better-genshin-impact · error · InvalidOperationException

Hotkey already registered

Error message

Hotkey already registered

What it means

User32.RegisterHotKey returned false and Marshal.GetLastWin32Error() is ERROR_HOTKEY_ALREADY_REGISTERED — the exact modifier+key combination is already owned globally by this or another process. Global hotkeys are system-wide unique per combination.

Source

Thrown at Fischless.HotkeyCapture/HotkeyHook.cs:56

        }
    }

    public HotkeyHook()
    {
        window.KeyPressed += (sender, args) =>
        {
            KeyPressed?.Invoke(this, args);
        };
    }

    public void RegisterHotKey(User32.HotKeyModifiers modifier, Keys key)
    {
        currentId += 1;
        if (!User32.RegisterHotKey(window!.Handle, currentId, modifier, (uint)key))
        {
            if (Marshal.GetLastWin32Error() == SystemErrorCodes.ERROR_HOTKEY_ALREADY_REGISTERED)
            {
                throw new InvalidOperationException("Hotkey already registered");
            }
            else
            {
                throw new InvalidOperationException("Hotkey registration failed");
            }
        }
    }

    public void UnregisterHotKey()
    {
        for (int i = currentId; i > 0; i--)
        {
            User32.UnregisterHotKey(window!.Handle, i);
        }
    }

    public void Dispose()
    {

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Call UnregisterHotKey before registering a new combination to release the previous binding.
  2. On this specific error, prompt the user to pick a different hotkey combination.
  3. Detect ERROR_HOTKEY_ALREADY_REGISTERED and show a clear message instead of surfacing an unhandled exception.
Defensive patterns

Strategy: try-catch

Try / catch

try
{
    hook.RegisterHotKey(hotkey.ModifierKey, hotkey.Key);
}
catch (InvalidOperationException ex) when (ex.Message == "Hotkey already registered")
{
    // prompt user for a different combination
}

Prevention

When it happens

Trigger: Another instance of the app already registered the same combination; a different application or the OS owns the same global hotkey; the app registered the hotkey and failed to unregister it before re-registering.

Common situations: Two app instances running simultaneously; hotkey conflict with screenshot/overlay/launcher tools; re-registration path that skips UnregisterHotKey.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/4bad97571cce5e4c. Report an issue: GitHub.