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
- 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.
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
- 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.
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
- Hotkey registration failed
- 动作 {snapshot.Description} 执行 {attempts} 次后,等待 {snapshot.Targ
- 鼠标限制区域必须具有有效宽度和高度。
- 临时解除本地鼠标限制失败
- 注册 Raw Input 鼠标设备失败
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/4bad97571cce5e4c.
Report an issue: GitHub.