Wednesday, May 12, 2021

Autohotkey, mouse button different action, click vs hold

;// This is the "back" button ...
;// Keywait waits max 210ms for key release. 
;// IF: (keywait < 200ms) -> send the actual button, IF: (keywait > 200ms (or timeout)) -> send key PageUp.
XButton1::
    x:=A_TickCount
    Keywait XButton1, T0.21
    d:=(A_TickCount-x)
    If (d<200)
        Send {XButton1}
    Else
        Send {PgUp}
Return

;// This is the "forward"-button ...
;// Keywait waits max 210ms for key release.
;// IF: (keywait < 200ms) -> send the actual button, IF: (keywait > 200ms (or timeout)) -> press the 1-button down, repeat.
XButton2::
    x:=A_TickCount
    Keywait XButton2, T0.21
    d:=(A_TickCount-x)
    If (d<200)
        Send {Xbutton2}
    Else
        Send {1 Down}
Return

;// When "forward" is released, the 1-button is released ...
XButton2 Up::
    Send {1 Up}
Return