evilC / TapHoldManager

An AHK library for Long Press / Multi tap / Multi tap and hold
MIT License
124 stars 13 forks source link

Multi taps and Shift key #1

Closed aaaxx closed 5 years ago

aaaxx commented 5 years ago

I'm trying to use Shift multitapping for different kinds of brackets, but i can't get the hold option to work like normal Shift.

#include Lib\TapHoldManager.ahk

thm := new TapHoldManager(, , 3)
thm.Add("LShift", Func("LShiftFunc"))
thm.Add("RShift", Func("RShiftFunc"))
return

LShiftFunc(isHold, taps){
    if (isHold){
        Send {LShift}
    } else {
        if (taps == 1){
            Send (
        } else if (taps == 2){
            Send {{} ; brace escape
        } else if (taps == 3){
            Send [
        }
    }
}

RShiftFunc(isHold, taps){
    if (isHold){
        Send {RShift}
    } else {
        if (taps == 1){
            Send )
        } else if (taps == 2){
            Send {}}
        } else if (taps == 3){
            Send ]
        }
    }
}
evilC commented 5 years ago

Of course not, because you removed the state parameter from your function, which tells you when the hold begins and ends

    if (isHold){
        Send {LShift} ; Presses AND RELEASES shift
    }

You want

LShiftFunc(isHold, taps, state){ ; state tells you when the hold starts and ends
    if (isHold){
        if (state){
            Send {LShift down}
        } else {
            Send {LShift up}
        }
    ...
}