ImageSearch errorLevel 2 question

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
lkb3
Posts: 73
Joined: 13 Mar 2014, 16:17

ImageSearch errorLevel 2 question

06 Dec 2023, 15:37

What are some of the reasons that ImageSearch might throw errorLevel 2?
The help file says:
"ErrorLevel is set to ... 2 if there was a problem that prevented the command from conducting the search (such as failure to open the image file or a badly formatted option)."

I have a script that was working fine to automate tasks in a web-based product data management program, until we upgraded to the newest version this week. Now it's having all sorts of troubles. So I built a simple test script to see if I could further diagnose it:

Code: Select all

coordmode, screen
SetWorkingDir, C:\Users\%A_UserName%\Documents\TCAWS_MENUICONS\


#!c::
	ImageSearch, thisX, thisY, 0, 1920, 0, 1280, *100 "tcaws_submit_button.png"
	msgbox %errorLevel%
return
C:\Users\<username redacted>\Documents\TCAWS_MENUICONS\tcaws_submit_button.png
is right there in the correct directory, and it coninues to throw errorLevel 2.
What else should I be looking at?
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: ImageSearch errorLevel 2 question

06 Dec 2023, 15:39

Remove the quotes on the image filename. "
lkb3
Posts: 73
Joined: 13 Mar 2014, 16:17

Re: ImageSearch errorLevel 2 question

06 Dec 2023, 15:52

tried that. Doesn't make a difference. Still throws errorLevel 2
User avatar
andymbody
Posts: 939
Joined: 02 Jul 2017, 23:47

Re: ImageSearch errorLevel 2 question

06 Dec 2023, 15:56

Fyi... I don't think this is correct

coordmode, screen


Try

Code: Select all

Coordmode, pixel, screen
Coordmode, mouse, screen
gregster
Posts: 9086
Joined: 30 Sep 2013, 06:48

Re: ImageSearch errorLevel 2 question

06 Dec 2023, 15:56

Xtra is right. Remove the quotes around the file name.
In AHK v1, you would only add quotes to a string in a command parameter (contrary to functions), if explicitly documented (like for Run), or if you force an expression.

Fo testing, you can also try it with a full path. Also check what A_username actually returns...perhaps there is the problem.
User avatar
andymbody
Posts: 939
Joined: 02 Jul 2017, 23:47

Re: ImageSearch errorLevel 2 question

06 Dec 2023, 16:08

Fix X1,Y1,X2,Y2. The coordinates you have here create a straight line from bottom towards the top of screen on far left side of screen.

ImageSearch, thisX, thisY, 0, 1920, 0, 1280


Should it be this instead?
ImageSearch, thisX, thisY, 0, 0, 1920, 1280
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: ImageSearch errorLevel 2 question

06 Dec 2023, 19:16

andymbody wrote:
06 Dec 2023, 16:08
Fix X1,Y1,X2,Y2. The coordinates you have here create a straight line from bottom towards the top of screen on far left side of screen.
That would cause :arrow: ErrorLevel = 2 for sure.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: dogbar492 and 200 guests