babalae/better-genshin-impact · warning · ArgumentException
Invalid Hotkey
Error message
Invalid Hotkey
What it means
Thrown by the Hotkey(string) constructor when parsing the hotkey string fails — Enum.Parse throws for an unrecognized key token, or the split/format is invalid. The catch-all swallows the original exception and rethrows a generic ArgumentException("Invalid Hotkey"), discarding which token actually failed.
Source
Thrown at Fischless.HotkeyCapture/Hotkey.cs:73
Control = true;
}
else if (keyStr.Equals("Shift", StringComparison.OrdinalIgnoreCase))
{
Shift = true;
}
else if (keyStr.Equals("Alt", StringComparison.OrdinalIgnoreCase))
{
Alt = true;
}
else
{
Key = (Keys)Enum.Parse(typeof(Keys), keyStr);
}
}
}
catch
{
throw new ArgumentException("Invalid Hotkey");
}
}
public override string ToString()
{
string str = string.Empty;
if (Key != Keys.None)
{
str = string.Format("{0}{1}{2}{3}{4}",
Windows ? "Win + " : string.Empty,
Control ? "Ctrl + " : string.Empty,
Shift ? "Shift + " : string.Empty,
Alt ? "Alt + " : string.Empty,
Key);
}
return str;
}
View on GitHub (pinned to a7cb36712d)
Solutions
- Validate the hotkey string format before constructing Hotkey; reject unknown tokens early.
- Replace Enum.Parse with Enum.TryParse and report which token failed instead of a generic message.
- Sanitize/normalize stored hotkey strings on config load (trim, collapse '+', reject empties).
Example fix
// before
Key = (Keys)Enum.Parse(typeof(Keys), keyStr);
// ... catch { throw new ArgumentException("Invalid Hotkey"); }
// after
if (!Enum.TryParse(typeof(Keys), keyStr, true, out var parsedKey))
throw new ArgumentException($"Invalid key token: '{keyStr}'", nameof(keyStr));
Key = (Keys)parsedKey; Defensive patterns
Strategy: try-catch
Validate before calling
foreach (var tok in hotkeyStr.Replace(" ", "").Split('+'))
{
if (modifiers.Contains(tok, StringComparer.OrdinalIgnoreCase)) continue;
if (!Enum.TryParse(typeof(Keys), tok, true, out _))
return false; // invalid token, do not construct Hotkey
}
return true; Type guard
static bool IsValidHotkeyString(string s)
{
if (string.IsNullOrWhiteSpace(s)) return false;
foreach (var tok in s.Replace(" ", "").Split('+'))
{
if (tok is "Win" or "Ctrl" or "Shift" or "Alt") continue;
if (!Enum.TryParse(typeof(Keys), tok, true, out _)) return false;
}
return true;
} Try / catch
Hotkey? hk = null;
try { hk = new Hotkey(stored); }
catch (ArgumentException) { hk = new Hotkey(); /* reset to empty/default */ } Prevention
- Use Enum.TryParse instead of Enum.Parse to avoid the catch-all.
- Validate hotkey strings before persisting them to config.
- Preserve the offending token in the error message for easier diagnosis.
When it happens
Trigger: A persisted hotkey string contains a token that is not a valid System.Windows.Forms.Keys name: a typo, a localized key name, an unknown function key, or an empty token from a trailing '+' delimiter.
Common situations: Config file hand-edited with a bad key string; locale mismatch producing a non-English key name; a key name removed in a newer framework; an empty or modifier-only hotkey string saved to disk.
Related errors
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/3c68d517d976f651.
Report an issue: GitHub.