AHK脚本故障求助:LAlt+Shift+a无法输出预期的Ctrl+Shift+a
AutoHotkey: Fixing LAlt+Shift+a/b Not Sending Ctrl+Shift+a/b
Original Code
*Lalt::return #if GetKeyState("Lalt", "P") a:: b:: if GetKeyState("shift", "P") send ^+{%A_ThisHotkey%} else Send ^{%A_ThisHotkey%} return #if
Issues Identified
- Nested Hotkey Syntax Error: The
b::hotkey is incorrectly nested insidea::, so it only activates after pressinga—not intended for independenta/bhotkeys. - Unshifted Hotkey Limitation:
a::doesn’t trigger when Shift is held (since Shift+a producesA, nota), so the code never runs for LAlt+Shift+a. - Invalid Key Reference: Using
%A_ThisHotkey%includes the hotkey’s modifiers (like*), leading to invalid key names in the Send command. - Native Alt+Shift Leak: Pressing Shift first then LAlt lets the system process Alt+Shift before AHK can intercept it, even with the
*modifier onLalt::return.
Corrected Code
*LAlt::return ; Disable native Alt functionality entirely #If GetKeyState("LAlt", "P") *a:: *b:: key := SubStr(A_ThisHotkey, 2) ; Extract the base key (remove leading *) if (GetKeyState("Shift", "P")) { Send {Blind}^+%key% } else { Send {Blind}^%key% } return #If
Key Fixes Explained
- Top-Level Hotkeys:
*a::and*b::are now separate, context-sensitive hotkeys that activate whenever LAlt is held. *Modifier on a/b: Ensures the hotkeys trigger regardless of other modifiers (like Shift), so LAlt+Shift+a/b is caught properly.- Key Extraction:
SubStr(A_ThisHotkey, 2)gets the actual key (e.g.,afrom*a) to avoid invalid Send commands. {Blind}in Send: Preserves existing modifier states while adding Ctrl, ensuring Ctrl+Shift+a/b is sent correctly without overriding Shift.*on LAlt: Guarantees theLAlt::returnhotkey triggers even when Shift is held first, blocking native Alt+Shift behavior.
内容的提问来源于stack exchange,提问作者Harry_Cyrus
相关产品推荐
相关产品推荐

