Passing an ImageFile through a variable Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Zee
Posts: 1
Joined: 24 Jun 2021, 21:41

Passing an ImageFile through a variable

24 Jun 2021, 22:17

What I am trying to do is have a function which takes a parameter which would be the file name for an image to be used by ImageSearch but I'm not sure what the proper syntax is so the program interprets it as the location for the image so it can use it in the ImageSearch.

Code: Select all

Scan(img)
{
	ImageSearch, foundx, foundy, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, %A_WorkingDir%\images\%img%.png
	If ErrorLevel = 0
		MouseClick Left, %foundx%, %foundy%, 1, 1
}

$F1 Up::
{
	Scan(nameofpngfile1)
	Scan(nameofpngfile2)
}
If it was not clear, I want it to do something like this, but I instead want to use a function like in the code above so I can repeat the action with multiple images that way it's less cluttered

Code: Select all

$F1 Up::
{
	ImageSearch, foundx, foundy, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, %A_WorkingDir%\images\picture1.png
	If ErrorLevel = 0
		MouseClick Left, %foundx%, %foundy%, 1, 1

	ImageSearch, foundx, foundy, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, %A_WorkingDir%\images\picture2.png
	If ErrorLevel = 0
		MouseClick Left, %foundx%, %foundy%, 1, 1
}
Last edited by Zee on 25 Jun 2021, 17:36, edited 1 time in total.
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Passing an ImageFile through a variable  Topic is solved

25 Jun 2021, 01:53

Code: Select all

Scan(img)
{
	ImageSearch, foundx, foundy, 0, 0, A_ScreenWidth, A_ScreenHeight, *30 %A_WorkingDir%\images\%img%.PNG
	If ErrorLevel = 0
		MsgBox, Found !
	else
		MsgBox, Not Found ! %img%.png
	return	
}

$F1 Up::
{
	Scan("nameofimage1")
Scan("nameofimage2")
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 211 guests