{"record":{"id":"4bad97571cce5e4c","repo":"babalae/better-genshin-impact","slug":"hotkey-already-registered","errorCode":null,"errorMessage":"Hotkey already registered","messagePattern":"Hotkey already registered","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Fischless.HotkeyCapture/HotkeyHook.cs","lineNumber":56,"sourceCode":"        }\n    }\n\n    public HotkeyHook()\n    {\n        window.KeyPressed += (sender, args) =>\n        {\n            KeyPressed?.Invoke(this, args);\n        };\n    }\n\n    public void RegisterHotKey(User32.HotKeyModifiers modifier, Keys key)\n    {\n        currentId += 1;\n        if (!User32.RegisterHotKey(window!.Handle, currentId, modifier, (uint)key))\n        {\n            if (Marshal.GetLastWin32Error() == SystemErrorCodes.ERROR_HOTKEY_ALREADY_REGISTERED)\n            {\n                throw new InvalidOperationException(\"Hotkey already registered\");\n            }\n            else\n            {\n                throw new InvalidOperationException(\"Hotkey registration failed\");\n            }\n        }\n    }\n\n    public void UnregisterHotKey()\n    {\n        for (int i = currentId; i > 0; i--)\n        {\n            User32.UnregisterHotKey(window!.Handle, i);\n        }\n    }\n\n    public void Dispose()\n    {","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/Fischless.HotkeyCapture/HotkeyHook.cs#L38-L74","documentation":"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.","triggerScenarios":"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.","commonSituations":"Two app instances running simultaneously; hotkey conflict with screenshot/overlay/launcher tools; re-registration path that skips UnregisterHotKey.","solutions":["Call UnregisterHotKey before registering a new combination to release the previous binding.","On this specific error, prompt the user to pick a different hotkey combination.","Detect ERROR_HOTKEY_ALREADY_REGISTERED and show a clear message instead of surfacing an unhandled exception."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    hook.RegisterHotKey(hotkey.ModifierKey, hotkey.Key);\n}\ncatch (InvalidOperationException ex) when (ex.Message == \"Hotkey already registered\")\n{\n    // prompt user for a different combination\n}","preventionTips":["Always UnregisterHotKey before re-registering a combination.","Prevent multiple app instances from registering the same global hotkey.","On conflict, guide the user to choose an unused combination."],"tags":["hotkey","win32","registration"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}