{"record":{"id":"9ebd9356a6f30f41","repo":"babalae/better-genshin-impact","slug":"error-9ebd93","errorCode":null,"errorMessage":"不支持的原琴按键","messagePattern":"不支持的原琴按键","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/GameTask/Music/Service/KeyInputTransports.cs","lineNumber":93,"sourceCode":"            'I' => User32.VK.VK_I,\n            'J' => User32.VK.VK_J,\n            'K' => User32.VK.VK_K,\n            'L' => User32.VK.VK_L,\n            'M' => User32.VK.VK_M,\n            'N' => User32.VK.VK_N,\n            'O' => User32.VK.VK_O,\n            'P' => User32.VK.VK_P,\n            'Q' => User32.VK.VK_Q,\n            'R' => User32.VK.VK_R,\n            'S' => User32.VK.VK_S,\n            'T' => User32.VK.VK_T,\n            'U' => User32.VK.VK_U,\n            'V' => User32.VK.VK_V,\n            'W' => User32.VK.VK_W,\n            'X' => User32.VK.VK_X,\n            'Y' => User32.VK.VK_Y,\n            'Z' => User32.VK.VK_Z,\n            _ => throw new ArgumentOutOfRangeException(nameof(key), key, \"不支持的原琴按键\")\n        };\n    }\n}\n\npublic sealed class PostMessageKeyInputTransport : KeyInputTransportBase\n{\n    public override MusicInputMode Mode => MusicInputMode.BackgroundPostMessage;\n\n    protected override void SendKeyDown(User32.VK key)\n    {\n        TaskContext.Instance().PostMessageSimulator.KeyDownBackground(key);\n    }\n\n    protected override void SendKeyUp(User32.VK key)\n    {\n        TaskContext.Instance().PostMessageSimulator.KeyUpBackground(key);\n    }\n}","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/Music/Service/KeyInputTransports.cs#L75-L111","documentation":"Thrown by KeyInputTransportBase.ToVirtualKey when the character passed to KeyDown or KeyUp is not one of the 26 uppercase letters A-Z. The switch expression only maps A-Z to virtual key codes; any other character (digit, symbol, lowercase letter that somehow bypassed ToUpper, or non-ASCII) hits the default arm and throws ArgumentOutOfRangeException.","triggerScenarios":"Calling KeyDown(c) or KeyUp(c) where c (after ToUpperInvariant) is outside 'A'-'Z'. This happens if the music score contains notes mapped to characters outside the 26-letter range, or the score parser produces an unexpected character.","commonSituations":"A music score file references keys like digits (1-9) or symbols that are not in the A-Z mapping; a MIDI-to-key mapping produces a character outside the supported set; the score format is keyboard-type but uses non-letter note names.","solutions":["Filter notes to only SupportedKeys ('QWERTYUASDFGHJZXCVBNM' as defined in MusicScoreParser) before sending them to the transport.","Validate the key character against 'A'-'Z' before calling KeyDown/KeyUp and skip invalid keys with a warning.","Extend ToVirtualKey to support additional virtual key codes if the score format legitimately uses them.","Inspect the score file for unexpected note characters."],"exampleFix":"// before\npublic void KeyDown(char key)\n{\n    key = char.ToUpperInvariant(key);\n    lock (_syncRoot)\n    {\n        if (!_pressedKeys.Add(key)) return;\n        SendKeyDown(ToVirtualKey(key));\n    }\n}\n\n// after — guard against unsupported keys\npublic void KeyDown(char key)\n{\n    key = char.ToUpperInvariant(key);\n    if (key < 'A' || key > 'Z') return; // silently skip unsupported\n    lock (_syncRoot)\n    {\n        if (!_pressedKeys.Add(key)) return;\n        SendKeyDown(ToVirtualKey(key));\n    }\n}","handlingStrategy":"validation","validationCode":"// Before sending key\nkey = char.ToUpperInvariant(key);\nif (key < 'A' || key > 'Z')\n{\n    logger.LogWarning(\"不支持的音乐按键：{Key}\", key);\n    return;\n}","typeGuard":"static bool IsSupportedKey(char key) => key >= 'A' && key <= 'Z';","tryCatchPattern":"try { transport.KeyDown(c); }\ncatch (ArgumentOutOfRangeException ex) { logger.LogWarning(ex, \"跳过不支持的按键\"); }","preventionTips":["Filter notes against SupportedKeys before sending to the transport.","Validate score files to only contain A-Z note characters.","Use the SupportedKeys constant from MusicScoreParser for consistency."],"tags":["music","input","argument-out-of-range","validation"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}