{"record":{"id":"ff015606c23c83d9","repo":"babalae/better-genshin-impact","slug":"vk","errorCode":null,"errorMessage":"未指定按键，无法转换为VK。","messagePattern":"未指定按键，无法转换为VK。","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/Config/KeyBindingsConfig.cs","lineNumber":433,"sourceCode":"            KeyId.Subtract => \"Num -\",\n            KeyId.Add => \"Num +\",\n            KeyId.NumEnter => \"Num Enter\",\n            // 默认使用枚举名\n            _ => value.ToString(),\n        };\n    }\n\n    /// <summary>\n    /// 将KeyId转换为VK\n    /// </summary>\n    /// <param name=\"value\"></param>\n    /// <returns></returns>\n    public static VK ToVK(this KeyId value)\n    {\n        return value switch\n        {\n            // 这两个值在VK中没有，抛异常\n            KeyId.None => throw new ArgumentOutOfRangeException(nameof(value), \"未指定按键，无法转换为VK。\"),\n            KeyId.Unknown => throw new ArgumentOutOfRangeException(nameof(value), \"未知按键，无法转换为VK。\"),\n            // 剩下的值相同，直接转\n            _ => (VK)value,\n        };\n    }\n\n    /// <summary>\n    /// 将KeyId转换为System.Windows.Input.Key\n    /// </summary>\n    /// <param name=\"value\"></param>\n    /// <returns></returns>\n    public static Key ToInputKey(this KeyId value)\n    {\n        // 部分按键名称相同，使用名称转换\n        try\n        {\n            return Enum.Parse<Key>(value.ToString());\n        }","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Config/KeyBindingsConfig.cs#L415-L451","documentation":"KeyBindingsConfig.ToVK converts a KeyId (the app's input enum) to a Windows virtual-key code (VK). KeyId.None means no key was assigned, and KeyId.None has no corresponding VK code, so the conversion is meaningless and throws ArgumentOutOfRangeException. The remaining KeyId values share the same numeric values as VK, so they cast directly.","triggerScenarios":"Calling someKeyId.ToVK() when the KeyId was never set (still KeyId.None); deserialized key-binding config where a binding was left unset; hotkey features invoking ToVK on a placeholder value.","commonSituations":"Default config with unassigned hotkeys; scripts reading a binding before the user configured it; newly added KeyId values that default to None.","solutions":["Check for KeyId.None before calling ToVK and skip/handle the unassigned case.","Ensure config initialization assigns a real key to every binding used.","Use ToInputKey for keyboard keys when a System.Windows.Input.Key is what you need."],"exampleFix":"// before\nvar vk = binding.KeyId.ToVK();\n\n// after\nif (binding.KeyId == KeyId.None) return;\nvar vk = binding.KeyId.ToVK();","handlingStrategy":"validation","validationCode":"if (binding.KeyId == KeyId.None) return; // or throw a clearer config error\nvar vk = binding.KeyId.ToVK();","typeGuard":"static bool IsAssignedKey(KeyId k) => k != KeyId.None && k != KeyId.Unknown;","tryCatchPattern":"try { vk = keyId.ToVK(); }\ncatch (ArgumentOutOfRangeException) { /* key unassigned, skip */ }","preventionTips":["Guard KeyId.None/Unknown before any ToVK/ToInputKey call.","Initialize all hotkey config with real keys rather than leaving None.","Validate key bindings at config load."],"tags":["keybinding","vk","argument-validation","config"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}