Trouble auto clicking while pixel searching

Ask gaming related questions (AHK v1.1 and older)
Sysministrator
Posts: 4
Joined: 21 Jun 2017, 19:40

Trouble auto clicking while pixel searching

21 Jun 2017, 20:08

Hello, I have a simple script that searches for a pixel color and tracks it with a slight offset. That part works great. However, I am unable to get it to click in a random interval. I can get it to click once I let go of the key that i set (left alt) but it will only click one time. I would love it if someone could assist me with getting it to click in a random interval every 100ms to 250ms once the pixel search moves the mouse. I've been looking at tons of previous threads dating back to 2007 and I just can't seem to get it. Ideally the whole script will click every 100ms to 250ms after it moves the mouse due to pixel search while holding left alt. In the script below I tried to split the PixelSearch and the Mouse Click into separate button holds. They work separately but I want to incorporate the click into function while I hold left alt. The clicking and the random number segment was me experimenting with the script trying to at least get it to click. The pixel search works wonderfully. Thanks for any help I can get.

#NoEnv
; #Warn ;
SendMode Input
SetWorkingDir %A_ScriptDir%

~$Alt::
while (GetKeyState("Alt", "P"))
{
Cx := TargetX+5
Cy := TargetY+8
Zx := TargetX-6
MouseGetPos, posX, posY

PixelSearch, TargetX, TargetY, 640, 165, 1250, 750, 0x61683E, 5, Fast RGB
if (TargetX <= 1200)
{
MouseMove, Zx, Cy
}
if (TargetX >= 680)
{
MouseMove, Cx, Cy
}
}
return

~$LButton::
Random, delay, 100, 250
While (GetKeyState("LButton", "P"))
{
Click
Sleep, %delay%
}
return
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Trouble auto clicking while pixel searching

21 Jun 2017, 21:07

You should be checking if (ErrorLevel = 0) from your PixelSearch command.
if (TargetX <= 1200) will be true when the Pixelsearch does not find the color.

To get a random sleep when clicking move the random command into the while loop like so:

Code: Select all

~*LButton:: 

While (GetKeyState("LButton", "P"))
{
    Random, delay, 100, 250
    Click
    Sleep, %delay%
}

return
Also add * hotkey prefix to allow the hotkey to fire when a modifier is also down.
$ is not needed mouse buttons always use the mouse hook and can not activate themselves.

HTH
Sysministrator
Posts: 4
Joined: 21 Jun 2017, 19:40

Re: Trouble auto clicking while pixel searching

21 Jun 2017, 22:28

Thank you so much for the info. Do you know how I could incorporate the auto click function while alt is pressed rather than having to press left mouse button? Ideally I want it all to happen while holding left alt and no other button. Mouse clicks just doesn't seem to work at all for me while holding alt no matter how i try to add it in.

I have tried error level and even the use of Tooltip to try to get some sort of feedback. The delay that I added in after ErrorLevel = 0 seems to be working but it will not click still. I believe the delay is working because with the entire if statement added it seems to be slowing down the pixel search update rate as if it was waiting for the mouse click delay. It's very confusing why it's skipping over the MouseClick, Left line but using the delay line.

My script now looks as follows

#NoEnv
; #Warn ;
SendMode Input
SetWorkingDir %A_ScriptDir%
#IfWinActive, OSBuddy Pro

*~$Alt::
while (GetKeyState("Alt", "P"))
{
Cx := TargetX+5
Cy := TargetY+8
Zx := TargetX-6
MouseGetPos, posX, posY

PixelSearch, TargetX, TargetY, 670, 430, 840, 580, 0x61683E, 5, Fast RGB

if (TargetX <= 840)
{
MouseMove, Zx, Cy
}
if (TargetX >= 700)
{
MouseMove, Cx, Cy
}
if (ErrorLevel = 0)
{
Random, delay, 100, 250
MouseClick, Left
Sleep, %delay%
}
}
return
Sysministrator
Posts: 4
Joined: 21 Jun 2017, 19:40

Re: Trouble auto clicking while pixel searching

21 Jun 2017, 23:19

I just realized that i can just replace MouseMove with MouseClick, Left instead of moving the cursor and THEN clicking. However, I've ran into a new issue. Mouse clicking seems to be blocked completely while left alt is pressed down even though i'm not using BlockInput. I tried adding BlockInput, Off just in case and still could not click. Any help would be appreciated. Here is what my script looks like now.

#NoEnv
; #Warn ;
SendMode Input
SetWorkingDir %A_ScriptDir%
#IfWinActive, OSBuddy Pro

*~$Alt::
while (GetKeyState("Alt", "P"))
{
Cx := TargetX+5
Cy := TargetY+8
Zx := TargetX-6
MouseGetPos, posX, posY


PixelSearch, TargetX, TargetY, 670, 430, 840, 580, 0x61683E, 5, Fast RGB

if (TargetX <= 840)
{
Random, delay, 100, 250
MouseClick, Left, %Zx%, %Cy%
Sleep, %delay%
}
if (TargetX >= 700)
{
Random, delay, 100, 250
Mouseclick, Left, %Cx%, %Cy%
Sleep, %delay%
}
}
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Trouble auto clicking while pixel searching

22 Jun 2017, 01:14

Give this a try:

Code: Select all

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
SetBatchLines, -1

#IfWinActive, OSBuddy Pro
~$Alt::
    while (GetKeyState("Alt", "P"))
    {
        PixelSearch, TargetX, TargetY, 670, 430, 840, 580, 0x61683E, 5, Fast RGB
        if (ErrorLevel = 0)
		{
            if (TargetX <= 840)
                MouseClick, Left, TargetX-6, TargetY+8
            else if (TargetX >= 700)
                MouseClick, Left, TargetX+5, TargetY+8		
			Random, delay, 100, 250
			Sleep, delay
        }
    }
return
Note:
The 2nd use of TargetX ---> (TargetX >= 700) is only used from 841+ values.
Sysministrator
Posts: 4
Joined: 21 Jun 2017, 19:40

Re: Trouble auto clicking while pixel searching

22 Jun 2017, 09:36

Upon further testing I've determined it was the game that stopped that portion of the script. I changed MouseClick to MouseMove and used SendInput {LButton} to resolve the issue instead. Once i used that it started clicking wonderfully.

Here is the final script

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
SetBatchLines, -1

#IfWinActive, OSBuddy Pro
~$Alt::
while (GetKeyState("Alt", "P"))
{
PixelSearch, TargetX, TargetY, 670, 430, 840, 580, 0x61683E, 5, Fast RGB
if (ErrorLevel = 0)
{
if (TargetX <= 840)
MouseMove, TargetX-6, TargetY+8
SendInput {LButton}
if (TargetX >= 700)
MouseMove, TargetX+5, TargetY+8
SendInput {LButton}
Random, delay, 100, 250
Sleep, delay
}
}
return

Thanks for all the help and tips!

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 80 guests