Please help rewrite ImageSearchAl for ahk v2

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
aleks
Posts: 4
Joined: 28 May 2023, 06:26

Please help rewrite ImageSearchAl for ahk v2

Post by aleks » 10 Jun 2023, 13:59

Hello

Found ImageSearchAll example code viewtopic.php?p=391569#p391569
But it is for ahk v1, please help rewrite it for ahk v2. Thank you all in advance for your help
Alexei

User avatar
boiler
Posts: 16774
Joined: 21 Dec 2014, 02:44

Re: Please help rewrite ImageSearchAl for ahk v2

Post by boiler » 10 Jun 2023, 14:39

Try this:

Code: Select all

ImageSearchAll(imageFile, x1:=0, y1:=0, x2:="Screen", y2:="Screen", var:=0) {
	x2 := x2 = "Screen" ? A_ScreenWidth : x2
	y2 := y2 = "Screen" ? A_ScreenHeight : y2
	found := []
	y := y1
	loop {
		x := x1
	    lastFoundY := 0
		while f := ImageSearch( &foundX, &foundY, x, y, x2, y2, "*" var " " imageFile) {
			if (lastFoundY = 0 || lastFoundY = foundY) {
				found.Push(Map("x", foundx, "y", foundy))
				x := foundX + 1
				lastFoundY := foundY
			} else
				break
		}
		y := lastFoundY + 1
	} until (x = x1) && !f
	return found
}

Demo:

Code: Select all

#Requires AutoHotkey v2.0
#Include ImageSearchAll.ahk

Found := ImageSearchAll("mypic.png", 0, 0, 1000, 900)
for Each, Coord in Found
	MsgBox Coord["x"] "," Coord["y"]

Here's a better reference for the v1 version: viewtopic.php?f=6&t=100838

Here is where the v2 version can now be found: viewtopic.php?f=83&t=118415

aleks
Posts: 4
Joined: 28 May 2023, 06:26

Re: Please help rewrite ImageSearchAl for ahk v2

Post by aleks » 10 Jun 2023, 16:28

hello boiler.
Many thanks for your help. The function works great.
Aleksei.

Post Reply

Return to “Ask for Help (v2)”