Page 1 of 1

ImageSearch Persistent ErrorCode=2

Posted: 19 Sep 2019, 21:46
by SB1992
Hello everyone!

New to AutoHotkey and I cannot figure out what I am doing wrong here. From the ToolTip it is clear that I have 4 numbers that should work for Image Search, but the ErrorLevel is always 2.

Code: Select all

MouseX:=non
MouseY:=non
TopLeftX:=non
TopLeftY:=non
BottomRightX:=non
BottomRightY:=non

#Persistent
SetTimer, WatchCursor, 100
return

WatchCursor:
MouseGetPos, MouseX, MouseY
TopLeftX := MouseX-100
TopLeftY := MouseY+200
BottomRightX := MouseX+100
BottomRightY := MouseY
ImageSearch, OPX, OPY, %TopLeftX%, %TopLeftY%, %BottomRightX%, %BottomRightY%, Image.JPG
test=%ErrorLevel%
ToolTip,  %TopLeftX%  %TopLeftY%  %BottomRightX% %BottomRightX% %ErrorLevel%
The image file is in the same directory as the script. If anyone has a suggestion to fix this code (or even to clean it up) that would be fantastic!

Cheers!

-S

Re: ImageSearch Persistent ErrorCode=2  Topic is solved

Posted: 19 Sep 2019, 23:54
by Xtra
TopLeftX := MouseX-100
TopLeftY := MouseY+200
BottomRightX := MouseX+100
BottomRightY := MouseY

Your top left Y pos is lower than your bottom right Y pos. This cause your search area to not be a rectangle.

The next problem you will most likely have is using a .jpg image try using a lossless format such as .png or .bmp

HTH

Re: ImageSearch Persistent ErrorCode=2

Posted: 21 Sep 2019, 19:06
by SB1992
Thank you for making clear this issue! As Height (the max pixel) is at the bottom of my screen I need to subtract from Height to look higher.