How to Press and Hold Mouse Left Button for Scroll Down and Right Button for Scroll Down...

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
VISHALVODRO
Posts: 26
Joined: 02 Apr 2016, 05:53

How to Press and Hold Mouse Left Button for Scroll Down and Right Button for Scroll Down...

05 Feb 2022, 01:20

Hi there!

I am trying to make something like : When I browse Chrome, I want to Press and Hold Left Mouse Button for Scroll the page Down and Right Mouse Button for Scroll the page Up. And when Double Click Left Mouse button it will switch to Left Tab and Double Click Right Mouse button would switch to the Right one...

Please Help...

I saw this software which does the job.
https://www.highrez.co.uk/downloads/xmousebuttoncontrol.htm
amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: How to Press and Hold Mouse Left Button for Scroll Down and Right Button for Scroll Down...

05 Feb 2022, 05:57

Hi!
Lets imagine that you want to select some text in Chrome (e.g. you want to copy it to the Clipboard). So you hold down your left mouse button and smack in your mind how successfully will you select your text, you move your mouse cursor highlighting the text... F*ck! The page is scrolling down!!!
But imagine you've managed to survive and your nerves aren't totally destroyed yet. Next time you want to select that long mysterious word to google what does it mean. In Chrome, obviously. So you double-click on that word to select it... Holy devils! You have been tossed to a previous tab!
Is this behaviour of a script exactly what you want us to offer you?
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
VISHALVODRO
Posts: 26
Joined: 02 Apr 2016, 05:53

Re: How to Press and Hold Mouse Left Button for Scroll Down and Right Button for Scroll Down...

05 Feb 2022, 06:15

Ha Ha Ha!!! No dear, though the way you've explained the situation was ironic and funny!!! :P :P :P but I intended to change to Home/End key pressed instead of scrolling up/down and so on. Only I wanted to know how to get those command activated while holding down or double click event...
amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: How to Press and Hold Mouse Left Button for Scroll Down and Right Button for Scroll Down...

05 Feb 2022, 07:08

I'm glad that you've liked that a bit of humor and don't consider it redundant or demeaning or something like that 😉.
When I'll be at home, I'll offer you a couple of approaches that you may quite easily use constructing your complex press-press-hold hotkeys. Also you will be able to do what you asked with just your RButton alone.
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
VISHALVODRO
Posts: 26
Joined: 02 Apr 2016, 05:53

Re: How to Press and Hold Mouse Left Button for Scroll Down and Right Button for Scroll Down...

05 Feb 2022, 07:17

Hi! Thanks for the reply, it was indeed a presentable humor in return of an answer! :crazy: I often read your comments just to have a good laugh at my own self!!!

It was a good one though.

I am indeed grateful for your approach. Would wait for your response. Though I'd be home by that time, will see when sit on my desktop...
amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: How to Press and Hold Mouse Left Button for Scroll Down and Right Button for Scroll Down...

05 Feb 2022, 11:49

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
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: How to Press and Hold Mouse Left Button for Scroll Down and Right Button for Scroll Down...

05 Feb 2022, 15:59

You can make the script to respond your wishes faster by adjusting the Morse() function it a little bit to include a force exit after the first hold or after the third dot. Also you can use #If MouseIsOver("ahk_exe chrome.exe") instead of #IfWinActive, ahk_exe chrome.exe. In this case your hotkey will work if the mouse cursor is over chrome window while it can be inactive.

Code: Select all

Morse_holdAnd3DotsTerminate(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 {
		KeyWait %key%, T%tout%
		if (ErrorLevel) ; Long press (holding) was detected, we stop gathering our pattern.
		{	
			Pattern .= "-"
			if (keyUp)
				send, {%key% Up} ;KeyWait %key%
			break
		}
		Pattern .= "."
		if (Pattern = "...")	; We stop gathering our pattern after three dots (three short presses)
			break
		ToolTip, % Pattern,,, 12
		KeyWait %key%,DT%tout%
		If (ErrorLevel)
			break
	}
	ToolTip,,,,12
	Return Pattern
}

#If MouseIsOver("ahk_exe chrome.exe")
~RButton::
p := Morse_holdAnd3DotsTerminate`() 
; KeyWait, RButton
Switch, p {
	Case ".": gosub, AutoScrollOff ; 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
##If

AutoScroll:
send, {Esc}{%toSend%}
return

StartAutoScroll:
SetTimer, AutoScroll, 100
gosub, AutoScroll
return

~LButton::
~RButton::
~WheelDown::
~WheelUp:: gosub, AutoScrollOff ; stop scrolling

AutoScrollOff:
SetTimer, AutoScroll, Off ; stop scrolling
return 

MouseIsOver(WinTitle) {
    MouseGetPos,,, WinID
    return WinExist(WinTitle . " ahk_id " . WinID)
}
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: How to Press and Hold Mouse Left Button for Scroll Down and Right Button for Scroll Down...

05 Feb 2022, 16:32

And this is more stable version of the previous one:

Code: Select all

Morse_holdAnd3DotsTerminate(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 {
		KeyWait %key%, T%tout%
		if (ErrorLevel) ; Long press (holding) was detected, we stop gathering our pattern.
		{	
			Pattern .= "-"
			if (keyUp)
				send, {%key% Up}
			break
		}
		Pattern .= "."
		if (Pattern = "...")	; We stop gathering our pattern after three dots (three short presses)
			break
		ToolTip, % Pattern,,, 12
		KeyWait %key%,DT%tout%
		If (ErrorLevel)
			break
	}
	ToolTip,,,,12
	Return Pattern
}

#If MouseIsOver("ahk_exe chrome.exe")
~RButton::
p := Morse_holdAnd3DotsTerminate() 
; KeyWait, RButton
Switch, p {
	Case ".": AutoScrollToBeOn := false ; 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
#If

AutoScroll:
if AutoScrollToBeOn
	send, {Esc}{%toSend%} ; We send WheelDown or WheelUp
else SetTimer, AutoScroll, Off ; stop scrolling
return

StartAutoScroll:
AutoScrollToBeOn := true
SetTimer, AutoScroll, 100
gosub, AutoScroll
return

#if AutoScrollToBeOn
~LButton::
~WheelDown::
~WheelUp:: AutoScrollToBeOn := false 
#if 
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: How to Press and Hold Mouse Left Button for Scroll Down and Right Button for Scroll Down...

05 Feb 2022, 16:46

The second approach is based on Settimer for Hold labels On/Off and Key Up On/Off hotkeys. You can look at the example of it here:
viewtopic.php?p=435712#p435712
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
VISHALVODRO
Posts: 26
Joined: 02 Apr 2016, 05:53

Re: How to Press and Hold Mouse Left Button for Scroll Down and Right Button for Scroll Down...

07 Feb 2022, 03:13

Many more things happened since my last visit looks like. Lemme go through all these, will get back...

Thank you dear...

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Gorgrak, Leonardo_Portela and 125 guests