Infinite loop with mouse buttons Topic is solved

Ask gaming related questions (AHK v1.1 and older)
PlaceholderName
Posts: 5
Joined: 27 May 2023, 05:01

Infinite loop with mouse buttons

Post by PlaceholderName » 27 May 2023, 05:12

Hi everyone,

I'm looking to bind scripts to my mouse buttons, that only execute a function when a certain pixel is recognized on the screen.
When the pixel is not recognized or seen, the mouse buttons should behave as normal.
Right now I'm creating infinite loops though, where the function activates the trigger... Does anyone know a way how to fix this?

Code: Select all

Function(){
	; if the pixel is detected do something, else I want the RButton to behave like normal, the else is causing problems here
	PixelSearch, OutputVarX, OutputVarY, 788, 1008, 789, 1009, 0x9DB2A1, 1, Fast
	if (ErrorLevel = 0){
		While GetKeyState("RButton","P")
		{
			Send, {RButton Down}
			Sleep, % ran(30, 60)
			Send, {RButton Up}
			Sleep, % ran(30, 60)
			Click
			Sleep, % ran(30, 60)
		} 
	} else {
			While GetKeyState("RButton","P")
			{
			Send, {RButton Down}
			}
			Send, {RButton Up}
	}
	Return
}

RButton::
Function()
Return

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Infinite loop with mouse buttons

Post by mikeyww » 27 May 2023, 10:24

Welcome to this AutoHotkey forum!

Your second While block ends before the button is sent up, right? This means that it is always sent up when the search fails.

PlaceholderName
Posts: 5
Joined: 27 May 2023, 05:01

Re: Infinite loop with mouse buttons

Post by PlaceholderName » 28 May 2023, 11:38

Hi Mikey,

In the else I want to achieve normal mouse click behavior.
What the code does is it keeps the RButton pressed down while the keystate of RButton is "Pressed", and sends it up when the keystate changes (no longer pressed).

I'm not sure of this is the best way to achieve the normal clicking behavior, mainly looking for ways to only execute the code under "if (ErrorLevel = 0)" when the pixel is found, when the pixel is not found my RButtonn behavior should not be modified in any way shape or form.

Thanks for your help!


Post Reply

Return to “Gaming Help (v1)”