我的控制键卡住的情况有好几种,并且只有当我运行 AutoHotkey 时才会发生这种情况。这种情况发生在多个不同的修饰键上,包括 control (^)、windows (#) 和 alt (!) 键。
类似的问题之前已经发帖多次了: 1, 2, 3。存在一些解决方案,并且此处建议的解决方案部分帮助了我(降低了问题发生的频率),但控制键仍然偶尔会卡住。我尝试过的事情包括#InstallKeybdHook。
我有两个问题:
我已经尝试了上面建议的所有方法,并创建了我自己的 StuckKeyUp 函数版本 (如此处建议):
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
}
正如其他答案和我原来的答案中所建议的:
其他调试方法你可以尝试
#HotkeyModifierTimeout 影响热键修饰符的行为: Ctrl、Alt、Win 和 Shift。
通过添加行 #InstallKeybdHook 安装键盘挂钩。
使用 SendInput 方法。
将此代码放在脚本中的特定位置(在热键内) 发送控制键或定时器的定义)并查看 KeyHistory(关闭消息框后)在哪些情况下 钥匙卡住了:
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 {Ctrl Up}
MsgBox,,, Ctrl released
KeyHistory
}
}
覆盖您可以使用的所有修饰键
#Requires AutoHotkey v1.1
#NoEnv
#InstallKeybdHook
SendMode Input
Keys := "LControl,RControl,LAlt,RAlt,LWin,RWin,LShift,RShift"
SetTimer, ReleaseKeys, 500
; ....
RETURN ; === end of auto-execute section ===
; Your hotkeys here
; ....
ReleaseKeys:
Loop, parse, Keys, `,
{
If GetKeyState(A_LoopField) ; If the OS believes the key to be in (logical state)
{
If !GetKeyState(A_LoopField,"P") ; but the user isn't physically holding it down (physical state)
{
Send {%A_LoopField% Up}
MsgBox,,, %A_LoopField% released
KeyHistory
}
}
}
Return
我也遇到了这个问题(只有 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 按键按下和按键按下,而没有中间按键,则通常会激活一个菜单。为了防止这种情况,键盘或鼠标钩子可能会自动发送屏蔽键。
我添加了#InstallKeybdHook,一切都很好。详情请参阅下文。
https://www.autohotkey.com/docs/commands/_HotkeyModifierTimeout.htm
虽然 user3419297 的回答非常好,但我认为
blind keyup
调用并不能解决问题。
看起来
KeyHistory
命令会导致按键被释放。
当我使用没有
KeyHistory
的 user3419297 脚本版本时,它对我来说从来不起作用。相比之下,每次发生问题时,单独调用 KeyHistory
就足以解决问题。
这个问题突然开始出现在一个多年来一直顺利运行且我没有进行任何更改的脚本中。 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 键,耶!