You need to enable JavaScript to run this app. AHK脚本故障求助:LAlt+Shift+a无法输出预期的Ctrl+Shift+a
优惠活动
大模型
产品
解决方案
定价
更多

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

  1. Nested Hotkey Syntax Error: The b:: hotkey is incorrectly nested inside a::, so it only activates after pressing a—not intended for independent a/b hotkeys.
  2. Unshifted Hotkey Limitation: a:: doesn’t trigger when Shift is held (since Shift+a produces A, not a), so the code never runs for LAlt+Shift+a.
  3. Invalid Key Reference: Using %A_ThisHotkey% includes the hotkey’s modifiers (like *), leading to invalid key names in the Send command.
  4. Native Alt+Shift Leak: Pressing Shift first then LAlt lets the system process Alt+Shift before AHK can intercept it, even with the * modifier on Lalt::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., a from *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 the LAlt::return hotkey triggers even when Shift is held first, blocking native Alt+Shift behavior.

内容的提问来源于stack exchange,提问作者Harry_Cyrus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 04:36:04