RMB toggle after 1 second delay?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
VonDutchX
Posts: 3
Joined: 11 Apr 2021, 17:11

RMB toggle after 1 second delay?

11 Apr 2021, 17:18

Hi There,

I'm using this script:

Code: Select all

toggle_on := 0
*$RButton::
	toggle_on := !toggle_on
	if (toggle_on){
		Send {Blind}{RButton Down}
	} else {
		Send {Blind}{RButton Up}
	}
	return
*$RButton Up::
	; Block release events, do nothing
	return
[Mod edit: [code][/code] tags added.]

to toggle the RMB. Works great, but I want it to start the toggle only after I hold the RMB for 1 second. If I just click the RMB it should just work as a normal RMB.

Looked around but can't find it. Pls help.
User avatar
mikeyww
Posts: 26934
Joined: 09 Sep 2014, 18:38

Re: RMB toggle after 1 second delay?

11 Apr 2021, 18:43

Code: Select all

*RButton::
KeyWait, RButton, T1
Send % "{Blind}{RButton" (!ErrorLevel ? "}" : (toggle := !toggle) ? " down}" : " up}")
Return
VonDutchX
Posts: 3
Joined: 11 Apr 2021, 17:11

Re: RMB toggle after 1 second delay?

11 Apr 2021, 19:02

Works. Greatly appreciated!
VonDutchX
Posts: 3
Joined: 11 Apr 2021, 17:11

Re: RMB toggle after 1 second delay?

11 Apr 2021, 19:36

mikeyww wrote:
11 Apr 2021, 18:43

Code: Select all

*RButton::
KeyWait, RButton, T1
Send % "{Blind}{RButton" (!ErrorLevel ? "}" : (toggle := !toggle) ? " down}" : " up}")
Return
It has a small problem, when I click RMB it should RMB Down and up like a normal RMB. But if I hold down the RMB for 1 sec it should Toggle The RMB.
User avatar
mikeyww
Posts: 26934
Joined: 09 Sep 2014, 18:38

Re: RMB toggle after 1 second delay?

11 Apr 2021, 19:56

The script has the problem that if you toggle once followed by a short press, you have interrupted the toggled pair. You can adjust as needed into a regular long form for the conditional statements. You have the basic tools here: KeyWait with a timeout will tell you if the key is released before the timeout. If so, ErrorLevel is 0, otherwise 1. You can decide how you want to handle the scenario of the interrupted toggle pair.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ccqcl, Descolada, inseption86, mebelantikjaya and 339 guests