mouse to pixle loop Topic is solved

Ask gaming related questions (AHK v1.1 and older)
spafmagic
Posts: 3
Joined: 03 Feb 2017, 08:34

mouse to pixle loop

03 Feb 2017, 08:50

Hello... first timer here. I have been searching for a while now for something that can detect the color change of a pixel and make the mouse cursor move to that location. So far I've found examples of scripts where the cursor is either sent to what ever instance of color there is, or just when one specific pixel changes to that color. If anyone can help me out with a script that can monitor 4 pixels where the same color would be detected and move the mouse to each one as the color hits it consecutively that would be awesome! Time is of the essence though. It's for an event that won't last long in an MMO.

Best way I can describe the logic is;

if (specific key is pressed) then begin loop

if pixel 950, 506 = (hex code for white) then move mouse cursor to 950, 506

if pixel 950, 565 = (hex code for white) then move mouse cursor to 950, 565... (and so on.)

if (specific button is pressed) then end loop
spafmagic
Posts: 3
Joined: 03 Feb 2017, 08:34

Re: mouse to pixle loop

03 Feb 2017, 16:17

I realize this is a slight bump, but the time I submitted this may have been a bit on the late side.
bluce
Posts: 70
Joined: 01 Feb 2017, 13:23

Re: mouse to pixle loop

07 Feb 2017, 11:13

If it's not too late, I would like to ask a few questions: How close are the pixels to eachother? Are the pixels 100% white and not a shade of white?
It seems possible to make the script do what you are asking for, the only possible issue is that the mouse will click the top left corner of whatever is showing up, due to the way pixelsearch works. Because of that the click may not register on the objects hitbox.
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: mouse to pixle loop  Topic is solved

08 Feb 2017, 13:02

He does not need pixelsearch, he knows the coords.

Something like this should work

Code: Select all

pixel_coords := [{x: 950, y: 506}, {x: 950, y: 565}]	; Configure your coordinates here
search_col := 0xFFFFFF

macro_on := 0

F1::
	macro_on := !macro_on
	if (macro_on)
		GoSub, DoLoop
	return

DoLoop:
	Loop {
		if (!macro_on)
			break
		for i, coords in pixel_coords {
			PixelGetColor, col, % coords.x, % coords.y, RGB
			if (col == search_col){
				MouseClick,, % coords.x, % coords.y
			}
		}
		Sleep 10	; Try not to overload CPU
	}
	return
bluce
Posts: 70
Joined: 01 Feb 2017, 13:23

Re: mouse to pixle loop

08 Feb 2017, 14:17

evilC wrote:He does not need pixelsearch, he knows the coords.

Something like this should work

Code: Select all

pixel_coords := [{x: 950, y: 506}, {x: 950, y: 565}]	; Configure your coordinates here
search_col := 0xFFFFFF

macro_on := 0

F1::
	macro_on := !macro_on
	if (macro_on)
		GoSub, DoLoop
	return

DoLoop:
	Loop {
		if (!macro_on)
			break
		for i, coords in pixel_coords {
			PixelGetColor, col, % coords.x, % coords.y, RGB
			if (col == search_col){
				MouseClick,, % coords.x, % coords.y
			}
		}
		Sleep 10	; Try not to overload CPU
	}
	return
PixelSearch is faster(when searching a 1x1 area) and it can search for a certain variation of the color, which is very useful in games.
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: mouse to pixle loop

08 Feb 2017, 14:42

Code: Select all

loops := 100

a1 := 0
Loop % loops {
	QPX( True )
	PixelSearch, x, y, 0, 0, 0, 0, 0xFFFFFF
	a1 += QPX(false)
}
a1 /= loops

a2 := 0
Loop % loops {
	QPX( True )
	PixelGetColor, out, 1, 1, RGB
	a2 += QPX(false)
}
a2 /= loops

msgbox % "PixelSearch: " a1 "`nPixelGetColor: " a2

QPX( N=0 ) { ; Wrapper for QueryPerformanceCounter()by SKAN | CD: 06/Dec/2009
	Static F,A,Q,P,X ; www.autohotkey.com/forum/viewtopic.php?t=52083 | LM: 10/Dec/2009
	If	( N && !P )
		Return	DllCall("QueryPerformanceFrequency",Int64P,F) + (X:=A:=0) + DllCall("QueryPerformanceCounter",Int64P,P)
	DllCall("QueryPerformanceCounter",Int64P,Q), A:=A+Q-P, P:=Q, X:=X+1
	Return	( N && X=N ) ? (X:=X-1)<<64 : ( N=0 && (R:=A/X/F) ) ? ( R + (A:=P:=X:=0) ) : 1
}
With 1 loop, PixelGetColor seems faster.
With 100 loops, they seem about the same.

Neither are likely as fast as GDIP
spafmagic
Posts: 3
Joined: 03 Feb 2017, 08:34

Re: mouse to pixle loop

28 Jan 2019, 23:17

evilC wrote:
08 Feb 2017, 13:02
He does not need pixelsearch, he knows the coords.

Something like this should work

Code: Select all

pixel_coords := [{x: 950, y: 506}, {x: 950, y: 565}]	; Configure your coordinates here
search_col := 0xFFFFFF

macro_on := 0

F1::
	macro_on := !macro_on
	if (macro_on)
		GoSub, DoLoop
	return

DoLoop:
	Loop {
		if (!macro_on)
			break
		for i, coords in pixel_coords {
			PixelGetColor, col, % coords.x, % coords.y, RGB
			if (col == search_col){
				MouseClick,, % coords.x, % coords.y
			}
		}
		Sleep 10	; Try not to overload CPU
	}
	return
I hate to resurrect an old post, but I think a belated "Thank you" is in order. Life came up, along with someone I knew, who was working on the same thing unbeknownst to me at the time, provided a solution before any answers came from here. But, now that that is no longer available to me, this script, with a little tweaking, compiled into an EXE in combination with the use of GlovePie works just as effectively.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 65 guests