AutoHotkey causing control key to get stuck

我的未来我决定 提交于 2019-12-06 04:46:21

问题


I have several situations when my control key gets stuck, and it happens only when I have AutoHotkey running. This happens with multiple different modifier keys (# (windows) key, ! (alt) key especially).

Similar problems have been posted several times before: 1, 2, 3. Some solutions exists, and the one suggested here partially helped me (decreased the frequency of the problem), but the control key still gets stuck occasionally. Things I have tried include #InstallKeybdHook.

I have two questions:

  1. Is it possible to prevent this problem?
  2. Is there a good way to have AutoHotkey fix this as soon as it happens?

I have tried everything suggested above, and created my own version of a StuckKeyUp function (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 
}

回答1:


Among other debugging methods you can try this:

Put this code at specific positions in your script (within hotkey definitions that send the control key or in a timer)

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
    }
}

and look in the KeyHistory (after closing the message box) in which situations the key gets stuck.




回答2:


While user3419297's answer is very good, I think the blind keyup call is not what fixes the problem.

It appears that the KeyHistory command causes the keys to be released.

When I used a version of user3419297's script without KeyHistory, it never worked for me. In contrast, invoking KeyHistory alone has been sufficient to resolve the problem for me every time it has occured.




回答3:


I added #InstallKeybdHook and all was well. See below for details.

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



来源:https://stackoverflow.com/questions/49009176/autohotkey-causing-control-key-to-get-stuck

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!