Check the nearest coord with MyImagesearch

10/24/2013 20:09 fuso98#1
With MyImageSearch i can check how many images are on the screen.
It return a 2D array. How can i check the nearest coord to the center of my screen? I know that i need a For..to..Next Loop but can some one give me an example?
10/24/2013 20:49 alpines#2
Here
Code:
Local $aExampleCoordinates[5][2] = [[20, 120], [50, 500], [900, 450], [680, 450], [700, 400]], $aDifference[UBound($aExampleCoordinates, 1)], $iLowestDiff = @DesktopWidth + @DesktopHeight, $iEntry

For $i = 0 To UBound($aExampleCoordinates, 1) - 1
	$aDifference[$i] = Abs(@DesktopWidth / 2 - $aExampleCoordinates[$i][0]) + Abs(@DesktopHeight / 2 - $aExampleCoordinates[$i][1])
	If $aDifference[$i] < $iLowestDiff Then
		$iLowestDiff = $aDifference[$i]
		$iEntry = $i
	EndIf
Next

MsgBox(64, "Lowest Difference", "Array entry " & $iEntry & " contains the coordinates with the lowest difference of the screen center.")
MouseMove($aExampleCoordinates[$iEntry][0], $aExampleCoordinates[$iEntry][1], 100)
Entry 2 means the 3rd of the array because the array starts at index 0.

Anyway, it could have been done a lot better but I guess that's enough.