ImageSearch is searching whole screen when it shouldn't

Ask gaming related questions (AHK v1.1 and older)
OwlTowl
Posts: 1
Joined: 02 Jul 2020, 13:54

ImageSearch is searching whole screen when it shouldn't

02 Jul 2020, 14:08

Code: Select all

ImgSearch(image)
{
	ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, %image%
	
	if (ErrorLevel = 2)
		MsgBox Could not conduct the search.
	else if (ErrorLevel = 1)
		return false
	else
		return true
}
I have two windows on the left and right hand of my screen. On each window is an image. When I search for this image it detects the image on both windows, not just the active window.

I've read over and over that by default CoordMode is meant to be limit to a single active window, but this doesn't appear to be true. What am I doing wrong? It must be A_ScreenWidth and Height, right? If so, is there a constant for the current active window width and height?
Last edited by BoBo on 02 Jul 2020, 14:18, edited 1 time in total.
Reason: Moved to Gaming section.
User avatar
boiler
Posts: 16926
Joined: 21 Dec 2014, 02:44

Re: ImageSearch is searching whole screen when it shouldn't

02 Jul 2020, 14:15

Nowhere does it say that the default CoordMode is meant to limit searches to a single active window. It just bases the 0,0 point on the upper-left corner of the active window. You can search within any size rectangle you want using that as the defined 0,0 point.

If you want to limit it to a window, get the width and height of that window using WinGetPos so you can limit the size of the search rectangle appropriately.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 73 guests