The first approach isn't the most effective for your task but it will introduce you to an interesting concept called
Morse() function. You're encouraged to read about it here:
https://www.autohotkey.com/board/topic/15574-morse-find-hotkey-press-and-hold-patterns/
Instead of
0 and
1 I had to use dots and dashes to be able to use
Switch operator.
When you hold your RButton and release it, then it starts autoscroll down.
If you make a short press and then long press (hold) and release RButton, then it starts autoscroll up.
To turn autoscroll off, you need to press LButton or RButton or WheelDown or WheelUp.
To increase/decrease autoscroll speed just change
100 to another number of milliseconds here:
SetTimer, AutoScroll, 100
If you make double-press (two short presses) of RButton then it goes to a next tab.
If you make triple-press (three short presses) of RButton then it goes to a previous tab.
Of course, you can add commands to other patterns. Short press is a dot
., long press is a dash
-.
Code: Select all
Morse(timeout := 150) { ; https://www.autohotkey.com/board/topic/15574-morse-find-hotkey-press-and-hold-patterns/
tout := timeout/1000 ; I've replaced "01" to "-." to be able to use switch
key := RegExReplace(A_ThisHotKey,"[*~$#+!^]")
Loop {
t := A_TickCount
KeyWait %key%
Pattern .= A_TickCount-t > timeout ? "-" : "."
ToolTip, % Pattern,,, 12
KeyWait %key%,DT%tout%
If (ErrorLevel) {
ToolTip,,,,12
Return Pattern
}
}
}
#IfWinActive, ahk_exe chrome.exe
~RButton::
p := Morse()
;~ KeyWait, RButton
Switch, p {
Case ".": SetTimer, AutoScroll, Off ; stop scrolling
Case "..": send, {Esc}^{Tab} ; next tab
Case "...": send, {Esc}+^{Tab} ; previous tab
Case "-":
toSend = WheelDown ; We'll scroll down
gosub, StartAutoScroll
Case ".-":
toSend = WheelUp ; We'll scroll up
gosub, StartAutoScroll
Default: return
}
Return
#IfWinActive
AutoScroll:
send, {Esc}{%toSend%}
return
StartAutoScroll:
SetTimer, AutoScroll, 100
gosub, AutoScroll
return
~LButton::
~RButton::
~WheelDown::
~WheelUp:: SetTimer, AutoScroll, Off ; stop scrolling