AutoHotkey让控制键卡住了

时间:2018-02-27 12:51:40

标签: windows-10 autohotkey modifier-key

当我的控制键卡住时,我有几种情况,只有当我运行AutoHotkey时才会发生这种情况。这种情况发生在多个不同的修饰键(特别是#(windows)键,!(alt)键)。

之前已多次发布类似问题: 123。存在一些解决方案,the one suggested here partially helped me(降低问题的频率),但控制键偶尔会卡住。

我有两个问题:

  1. 是否可以防止此问题?
  2. 有没有一种好方法让AutoHotkey在发生这种情况时立即修复它?
  3. 我已经尝试了所有建议,并创建了我自己的StuckKeyUp函数版本(as suggested here

    StuckKeyUp(){
    sleep 300 
    send {<# up} 
    send {># up} 
    send {# up} 
    send {+ up} 
    send {<+ up} 
    send {! up} 
    send {<! up} 
    send {>! up} 
    send {^<^^>! up} 
    send {^<^>! up} 
    send {^ up} 
    send {Ctrl down} 
    send {Ctrl up}
    
    Send {§ up}         
    Send {Shift Up}
    Send {LShift Up}
    Send {RShift Up}
    Send {Alt Up}
    Send {LAlt Up}
    Send {RAlt Up}
    Send {Control Up}
    Send {LControl Up}  
    Send {<^ down}      
    Send {<^ Up}        ; solves some issues, but not all
    Send {>^ down}      
    Send {>^ Up}        
    Send {RControl Up}
    Send {LControl Up}
    Send {LWin Up}
    Send {RWin Up}
    sleep 100 
    ; reload, ; Avoid - Reloading AutoHotkey File causes functions depending on this function to break
    return 
    }
    

5 个答案:

答案 0 :(得分:4)

其他debugging methods 你可以试试这个:

将此代码放在脚本中的特定位置(在发送控制密钥或定时器的热键定义中)

If GetKeyState("Ctrl")           ; If the OS believes the key to be in (logical state),
{
    If !GetKeyState("Ctrl","P")  ; but  the user isn't physically holding it down (physical state)
    {
        Send {Blind}{Ctrl Up}
        MsgBox,,, Ctrl released
        KeyHistory
    }
}

并查看KeyHistory(在关闭消息框之后),在这种情况下密钥卡住了。

答案 1 :(得分:1)

虽然user3419297的回答非常好,但我认为blind keyup调用不是解决问题的方法。

似乎KeyHistory命令导致键被释放。

当我使用不带KeyHistory的user3419297脚本版本时,该脚本对我没有用。相反,每次调用KeyHistory都足以为我解决问题。

答案 2 :(得分:1)

我也遇到了这个问题(只有Ctrl被卡住了),对我来说,解决方法是在脚本顶部使用#MenuMaskKey:

;; Avoid Ctrl getting stuck in down state, even when not physically pressed:
#MenuMaskKey vkFF

https://www.autohotkey.com/docs/commands/_MenuMaskKey.htm的背景信息

掩码键会自动发送,以防止“开始”菜单或活动窗口的菜单栏在意外时间激活。

默认遮罩键是Ctrl。

...

如果系统仅检测到Win或Alt键按下和键输入而没有中间按键,则通常会激活菜单。为防止这种情况,键盘或鼠标挂钩可能会自动发送掩码键。

答案 3 :(得分:1)

这个问题突然开始出现在一个脚本中,该脚本多年来一直正常运行,我没有对其进行任何更改。 FWIW 它是在 Windows 更新之后启动的,该更新似乎稍微减慢了向应用程序发送击键的 AHK 和 python 脚本。每个人似乎都说不可能发生,但我知道我看到了什么。无论如何,我尝试了我能找到的所有方法,但没有任何效果,直到我将它放在脚本的开头:

^T:: ;Script starts here
    Sleep, 500
    Send {LCtrl Up}
    ;Script continues and Ctrl is no longer pressed :)

抱歉,我没有准确的技术解释来解释为什么会这样。我猜当我按下我的热键(在这种情况下是 Ctrl-T)时,我没有足够快地松开 Ctrl 键,但是它不知何故还没有完全注册到 AHK。无论如何,在发送密钥之前的那个小小的停顿似乎每次都有效。 500 毫秒是任意的;它有效,我没有费心试图让它更短。在每个脚本之后不再按 Ctrl,是的!

答案 4 :(得分:0)

我添加了#InstallKeybdHook,一切都很好。有关详情,请参见下文。

https://www.autohotkey.com/docs/commands/_HotkeyModifierTimeout.htm