autohotkeydouble-click

Why is AHK ignoring previous keys for sensitive spacebar?


I have a gaming keyboard where the keys trigger at the start of the press instead of at the end like with normal keyboards. For almost all of the keys this is absolutely fine, but the spacebar is particularly sensitive and while typing this I even got a triple-press from it.

Using AutoHotKey, I have a very basic code worked out for reading double spaces on input, and it works... after non-alphanumerical keys only. if, for example, I press "g space space", it'll write "g  " instead of "g ". clearly my code is too simple to cover for this.

:*:  ::
{
    Send {Space}
}
return  
#Escape:: 
ExitApp
return

I tried to brute-force it, by including :*:a  :: for example, but if I type "a a space space", the problem persists.


Solution

  • The real solution would be to open your keyboard's configuration software and tune the activation point for keys. If this is not available for your keyboard, honestly it's trash and you should invest in a real keyboard.

    But so my answer is not just off-topic rant, here is a workaround with AHK I cooked up:

    #Requires AutoHotkey v2
    
    HotIf(Callback)
    Hotkey("*Space", (*) => {})
    
    Callback(name)
    {
        static lastSpace := 0, minDelay := 500
    
        timeDiff := A_TickCount - lastSpace
    
        if (timeDiff >= minDelay)
            lastSpace := A_TickCount
    
        return (A_PriorHotkey == name || !A_PriorHotkey) && timeDiff <= minDelay
    }
    

    So essentially a context sensitive Hotkey to consume key presses.
    Triggers is there wasn't at least minDelay amount of ms between keypresses.