Mouse Hold-Toggle Inversion Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Oblituarius
Posts: 13
Joined: 31 Mar 2019, 16:57

Mouse Hold-Toggle Inversion

27 Jan 2020, 00:47

Hi everyone!

So I'm trying to invert how the mouse works, pretty much.
If I hold down RButton, I wamt to do a full click, but if I click once, I want to hold RButton down until I click RButton again.

This are some of the tests I've done so far and the last one is the one that was worked the best so far, problem is... it still sends RButton twice after I release it

First Attempt

Code: Select all

RButton up::
{
	toggle:=!toggle
	if (toggle)
	{
		Send {RButton down}
	}
	else
	{
		Send {RButton up}
	}
return
}

RButton::
{
	Sleep 100
	While GetKeyState("RButton", "P")
	{
		tooltip RButton Toggle
		Send {RButton down}
		Sleep 50
		Send {RButton up}
	}
	return
}

Second Attempt

Code: Select all

RButton::
Duration=0
Loop
{
	Duration ++
	If (Duration > 100)
	{
		Send {RButton down}
		Sleep 50
		Send {RButton up}
	}
	If (Duration < 100)
	{
		toggle:=!toggle
		if (toggle)
		{
			Send {RButton down}
		}
		else
		{
			Send {RButton up}
		}
	}
	If !GetKeyState("RButton","P")
	{
		return
	}
}

Maybe there is some software that does this? I haven't found one yet, but would rather have it on AHK.
Thanks for any help / tips!

Edit1:
I've somehow made it work partly, sometimes it doesn't click, might be me though

Code: Select all

$RButton::
{
	KeyWait, RButton, T0.099
	If (Errorlevel=0)
	{
		toggle:=!toggle
		if (toggle)
		{
			Send {RButton down}
		}
		else
		{
			Send {RButton up}
		}
		return
	}
	If (Errorlevel=1)
	{
		Send {RButton down}
		Sleep 50
		Send {RButton up}
		return
	}
	return
}
Rohwedder
Posts: 7705
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Mouse Hold-Toggle Inversion

27 Jan 2020, 02:59

Hallo,
try:

Code: Select all

RButton::
KeyWait, RButton
IF A_TimeSinceThisHotkey < 200
{
	IF Toggle:=!Toggle
		Send {RButton Down}
	Else
		Send {RButton Up}
}
Else
	Click, Right
Return
Oblituarius
Posts: 13
Joined: 31 Mar 2019, 16:57

Re: Mouse Hold-Toggle Inversion

27 Jan 2020, 12:18

Rohwedder wrote:
27 Jan 2020, 02:59
Hallo,
try:

Code: Select all

RButton::
KeyWait, RButton
IF A_TimeSinceThisHotkey< 200
{
	IF Toggle:=!Toggle
		Send {RButton Down}
	Else
		Send {RButton Up}
}
Else
	Click, Right
Return
Thanks for your reply!
This works great too! It works pretty much like the code on my Edit1, though this is very few lines in comparison, so thanks for it!

I'm still missing something though, the section for

Code: Select all

IF A_TimeSinceThisHotkey
never runs unless I release RButton. I would need it to run as soon as 100ms have gone by. No idea still on how to achieve that.
Will do some thinking and see if can figure it out / find some solution on the web.

Thanks! PS: Still accepting more help / suggestions
Rohwedder
Posts: 7705
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Mouse Hold-Toggle Inversion  Topic is solved

28 Jan 2020, 09:08

Then perhaps:

Code: Select all

RButton::
KeyWait, RButton, T.1 ; waits max. 100ms
IF ErrorLevel ; < 100ms
{
	IF Toggle:=!Toggle
		Send {RButton Down}
	Else
		Send {RButton Up}
	ToolTip,% GetKeyState("RButton")?"RButton Down":"RButton Up"
}
Else ; >= 100ms
{
	Click, Right
	ToolTip, RClick
}
SetTimer, ToolTip, -500
Return
ToolTip:
ToolTip
Return
Oblituarius
Posts: 13
Joined: 31 Mar 2019, 16:57

Re: Mouse Hold-Toggle Inversion

28 Jan 2020, 16:14

Works perfectly! Thank you very much! I actually managed to get to almost the same exact way you did it, but written a bit different. Will still use yours since it is much cleaner,
Much appreciated!

My Code:

Code: Select all

*RButton::
{
	KeyWait, RButton, T0.11
	If (Errorlevel=1)
	{
		Send {RButton down}
		KeyWait, RButton
		Send {RButton up}
		return
	}
	If (Errorlevel=0)
	{
		toggle:=!toggle
		if (toggle)
		{
			Send {RButton down}
			return
		}
		else
		{
			Send {RButton up}
			return
		}
		return
	}
return
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: CoffeeChaton, GEOVAN, LazyVovchik, peter_ahk, rubeusmalfoy and 126 guests