簡體   English   中英

AutoHotkey 導致控制鍵卡住

[英]AutoHotkey causing control key to get stuck

當我的控制鍵被卡住時,我有幾種情況,只有當我運行 AutoHotkey 時才會發生。 這發生在多個不同的修飾鍵上,包括控制 (^)、窗口 (#) 和 alt (.) 鍵。

類似的問題之前幾次1、2、3 存在一些解決方案, 這里建議的解決方案部分幫助了我(降低了問題的頻率),但控制鍵仍然偶爾會卡住。 我嘗試過的事情包括#InstallKeybdHook

我有兩個問題:

  1. 是否可以防止此問題?
  2. 有沒有什么好方法可以讓 AutoHotkey 在鍵被卡住時進行監控(例如,當鍵被按住超過 10 秒時自動通知)並在它發生時盡快修復它?

我已經嘗試了上面建議的所有方法,並創建了我自己的 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 
}

在其他調試方法中,您可以試試這個:

將此代碼放在腳本中的特定位置(在發送控制鍵或計時器的熱鍵定義中)

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(關閉消息框后)在哪些情況下鍵卡住了。

我也遇到了這個問題(只有 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 鍵按下和鍵彈起而沒有中間按鍵,它通常會激活一個菜單。 為了防止這種情況,鍵盤或鼠標鈎子可能會自動發送屏蔽鍵。

雖然 user3419297 的回答非常好,但我認為blind keyup調用並不能解決問題。

似乎是KeyHistory命令導致密鑰被釋放。

當我使用不帶KeyHistory的 user3419297 腳本版本時,它對我不起作用。 相比之下,每次發生問題時,單獨調用KeyHistory就足以為我解決問題。

我添加了#InstallKeybdHook,一切都很好。 詳情見下文。

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

這個問題突然開始出現在一個腳本中,這個腳本多年來一直沒有任何問題,我也沒有對其進行任何更改。 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,耶!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM