0
votes

i'm tring to get a key held for 300ms and active some action,but it keeps activing that action over and over again if i keep holding the key.

i've tried to use $ and A_TimeSincePriorHotkey,all didn't help.

$r::
    if (A_PriorHotkey = "r" and A_TimeSincePriorHotkey < 100)
            return

    keywait, r, T0.3

    if (ErrorLevel = 1)
    {
        GetKeyState, Mode, NumLock, T
        if (Mode="U")
            SetNumLockState ON
        else
            SetNumLockState OFF

        send {r up}
    }
    else
        send {r}
return
1

1 Answers

3
votes

Try this out. The only adjustment is adding the KeyWait, r This will cause the script to wait until the hotkey is released so that it's not constantly activating while the hotkey is pressed down as you described.

$r::
if (A_PriorHotkey = "~r" and A_TimeSincePriorHotkey < 100)
        return

keywait, r, T0.3

if (ErrorLevel = 1)
{
    GetKeyState, Mode, NumLock, T
    if (Mode="U")
        SetNumLockState ON
    else
        SetNumLockState OFF

    KeyWait, r
}
else
    send {r}
return