More reliably Pixel searching and clicking a moving target

Ask gaming related questions (AHK v1.1 and older)
Drknyss
Posts: 14
Joined: 21 Jan 2022, 16:32

More reliably Pixel searching and clicking a moving target

Post by Drknyss » 22 Jan 2022, 12:15

I am writing a script to automate clicking a moving blue circle. The circle moves randomly Left and Right at different speeds. While sometimes I am able to get decent results, others the circle moves too fast to click. From what I can tell, I believe the pixel search detects the circle towards the top and the click misses due to the circle moving. Does anyone have any thoughts on improving this to more reliably click the moving circle?

Code: Select all

SetMouseDelay,-1
SetBatchLines, -1
SetDefaultMouseSpeed 0

PixelSearch, Px, Py, %xpos1%, %ypos1%, %xpos2%, %ypos2%, 0xFF0000, 7, Fast ; Find Blue Button
		MouseClick, left, %Px%, %Py% ; Click on Blue Button		
Example of the circle:
Image
Last edited by Drknyss on 22 Jan 2022, 13:56, edited 1 time in total.

Rohwedder
Posts: 7552
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: More reliably Pixel searching and clicking a moving target

Post by Rohwedder » 22 Jan 2022, 13:47

Hallo,
your blue is in Blue-Green-Red (BGR) format: 0xFF0000

Drknyss
Posts: 14
Joined: 21 Jan 2022, 16:32

Re: More reliably Pixel searching and clicking a moving target

Post by Drknyss » 22 Jan 2022, 13:56

Ahh Thank you. Still seems to act the same way though.. The mouse clicks seem to be happening at the tip top of the circle... and even if I try to alter the mouse click position with pixels the mouse always seems to end up there.. Which I think is what is causing it to miss sometimes.

Rohwedder
Posts: 7552
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: More reliably Pixel searching and clicking a moving target

Post by Rohwedder » 23 Jan 2022, 02:18

The mouse clicks seem to be happening at the tip top of the circle...

Yes, this is to be expected according to the documentation:
https://www.autohotkey.com/docs/commands/PixelSearch.htm#Remarks
Fast mode: The search starts at the coordinates specified by X1 and Y1 and checks all pixels in the row from X1 to X2 for a match.

To click the center of the circle you should increase the found Y-value by the circle radius.

Post Reply

Return to “Gaming Help (v1)”