{"record":{"id":"9570eee36634872c","repo":"BluePointLilac/ContextMenuManager","slug":"hotkey-must-include-a-modifier-key","errorCode":null,"errorMessage":"Hotkey must include a modifier key.","messagePattern":"Hotkey must include a modifier key\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"warning","filePath":"ContextMenuManager/BluePointLilac.Methods/ShellLink.cs","lineNumber":215,"sourceCode":"                return description.ToString();\n            }\n            set\n            {\n                shellLinkW.SetDescription(value);\n            }\n        }\n\n        public Keys HotKey\n        {\n            get\n            {\n                shellLinkW.GetHotKey(out ushort key);\n                int hotKey = ((key & 0xFF00) << 8) | (key & 0xFF);\n                return (Keys)hotKey;\n            }\n            set\n            {\n                if((value & Keys.Modifiers) == 0) throw new ArgumentException(\"Hotkey must include a modifier key.\");\n                ushort key = unchecked((ushort)(((int)(value & Keys.Modifiers) >> 8) | (int)(value & Keys.KeyCode)));\n                shellLinkW.SetHotKey(key);\n            }\n        }\n\n        public FormWindowState WindowStyle\n        {\n            get\n            {\n                shellLinkW.GetShowCmd(out int style);\n                switch(style)\n                {\n                    case SW_SHOWMINIMIZED:\n                    case SW_SHOWMINNOACTIVE:\n                        return FormWindowState.Minimized;\n                    case SW_SHOWMAXIMIZED:\n                        return FormWindowState.Maximized;\n                    case SW_SHOWNORMAL:","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/BluePointLilac/ContextMenuManager/blob/55507155dd8e49c7ab4606da97f2af192d590dfe/ContextMenuManager/BluePointLilac.Methods/ShellLink.cs#L197-L233","documentation":"The ShellLink.HotKey setter enforces that any assigned hotkey must include at least one modifier key (Ctrl, Alt, or Shift). Windows shortcut (.lnk) hotkeys are encoded as a two-byte value where the high byte stores modifier flags and the low byte stores the virtual-key code. The library throws ArgumentException when (value & Keys.Modifiers) == 0 because a modifier-less hotkey would produce a zero high byte, yielding an ambiguous or ineffective shortcut key.","triggerScenarios":"Assigning shellLink.HotKey = Keys.F5 (or any single virtual key without OR-ing in Keys.Control, Keys.Alt, or Keys.Shift). Also triggered by assigning Keys.None or any Keys enum value whose bits do not overlap with the Keys.Modifiers mask (0x000F0000).","commonSituations":"Developer assigns a bare function key or letter key expecting the OS to apply a default modifier. Developer constructs the Keys value from an index or enum mapping that omits modifier bits. Passing a raw ConsoleKey or integer cast to Keys that lacks modifier flags.","solutions":["OR the desired key with a modifier: shellLink.HotKey = Keys.Control | Keys.F5","Pre-validate with: if((hotkey & Keys.Modifiers) != 0) before assigning","If you need a modifier-less shortcut, pick one of Keys.Control, Keys.Alt, or Keys.Shift as the minimum required companion"],"exampleFix":"// before\nshellLink.HotKey = Keys.F5;\n\n// after\nshellLink.HotKey = Keys.Control | Keys.F5;","handlingStrategy":"validation","validationCode":"static bool IsValidHotKey(Keys key)\n{\n    return (key & Keys.Modifiers) != 0\n        && (key & Keys.KeyCode) != 0;\n}\n\n// Usage:\nif(IsValidHotKey(desiredKey))\n    shellLink.HotKey = desiredKey;\nelse\n    ShowUser(\"Hotkey must include Ctrl, Alt, or Shift.\");","typeGuard":"static bool IsHotKeyWithModifier(Keys key) => (key & Keys.Modifiers) != 0;","tryCatchPattern":null,"preventionTips":["Always build hotkey values with explicit modifier OR: Keys.Control | Keys.F5","Centralize hotkey assignment behind a helper that validates modifier presence","Never cast a raw int or ConsoleKey directly to Keys for the HotKey property","Remember Keys.Modifiers is 0x000F0000 — any value below that bit range will fail"],"tags":["validation","shell-link","hotkey","windows","argument","winforms"],"backgroundTag":null,"analyzedSha":"55507155dd8e49c7ab4606da97f2af192d590dfe","analyzedAt":"2026-08-13T13:32:34.501Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}