Page 1 of 1

Mouse Hold-Toggle Inversion

Posted: 27 Jan 2020, 00:47
by Oblituarius
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
}

Re: Mouse Hold-Toggle Inversion

Posted: 27 Jan 2020, 02:59
by Rohwedder
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

Re: Mouse Hold-Toggle Inversion

Posted: 27 Jan 2020, 12:18
by Oblituarius
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

Re: Mouse Hold-Toggle Inversion  Topic is solved

Posted: 28 Jan 2020, 09:08
by Rohwedder
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

Re: Mouse Hold-Toggle Inversion

Posted: 28 Jan 2020, 16:14
by Oblituarius
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
}