Jump to content

Image Search


Recommended Posts

Hi all, 

I created a script in AHK and want to try to change it to AutoIt, mainly since it is on the Approved Software list of my company, where AutoHotKey isn't. 

My main question is basically the following, is there an equivalent function to the AHK Image Search function?

I use several instances of the following: 

Loop 10{ ;this loop checks for the text Order on the order, as it takes a little time to load, we wait 1 second 10 times. If it times out it stops otherwise it goes on to the next step
ImageSearch, CheckX, CheckY, 600, 230, 1000, 950, *2 FirstCheck.PNG
A11 := CheckX-100
A12 := CheckY+20
if (ErrorLevel = 2)
MsgBox Something went wrong
Else if (ErrorLevel = 0)
Goto Step3a
Sleep 1000
MsgBox Went through 10 sec wait, nothing found

This as the loading times are variable in the tool that we are using. 

I should be able to make a work around with the PixelSearch function, but that will be a bit messy I think. 

Any help would be greatly appreciated. 

Link to comment
Share on other sites

We have a tool that we need to use in a rather manual process, I am automating the process by clicking on buttons in the tool and entering text in fields. 

As it all happens inside the tool there are no pop-ups or other messages that I can use. 

So at the moment it works as follows: 

Enter a number, hit enter, wait for the first information to load. 

Click on a button in the tool that has appeared. 

Wait for more information to load. 

Click on another button that has appeared in the tool. 

Wait for more information to load. 

Scroll all the way down and click more buttons and 2 dropdown menu 

Then enter numbers, this could be just one line or up to 30. 

The function in my first post is the second wait. 

Link to comment
Share on other sites

We can probably help you with your script. As for the more reliable methods, I suggest trying AutoIt Window Info Tool (try both the x64 and x86 versions). It should be in your start menu in the section for AutoIt v3. Try dragging it's Finder Tool and hovering over the buttons in your program. If the Finder Tool finds things like Title, Class and Instance, then your program can probably be automated fairly easily. If the Finder Tool cannot read the buttons, we can resort to the old key presses and searching for colors. Believe me, once you get ControlClicks working well with your program, you won't want to go back to the unreliable ways of automating.

Link to comment
Share on other sites

The tool was made by a developer whom I never met, but dislike with a fiery passion... 

Decisions were made, that are questionable at best. We deal with money, but the fields to fill in the amounts DO NOT ACCEPT THE PASTE COMMAND....

Anyway, no luck it doesn't show anything inside the tool, so I will need to use the keypresses etc... 

Link to comment
Share on other sites

Sorry to leave you hanging for now, but I must go for the day. AutoIt does have an ImageSearch UDF located here. I have never worked with it, but I can play with it tonight. Like you said, the script can probably be done with PixelSearch. Perhaps someone else may be able to help while I'm gone. 

Link to comment
Share on other sites

Well, plans have changed for the day, so I’m back for a little bit. Another command you might want to look into is WinGetPos. If you do decide to use PixelSearch (which I would prefer since it’s a native function in AutoIt and will be supported in the future), this will be useful because you can use the window’s coordinates as an anchor. From there, you can look for the button’s position relative to the window.

Here’s some test code with Window’s Calculator. I don’t know if it will work the same on your computer as mine (we may have different a different OS or different DPI), but it works on my Win11 PC with 100% scaling. In the following example, it gets the color of the zero button before and after hovering over it. 

$sWinTitle = "Calculator" ; I tested with Windows' Calculator
$iButtonPosX = 250 + 10 ; added 10 to go into the button a little
$iButtonPosY = 275 + 10 ; same as above

$aWPos = WinGetPos($sWinTitle, "") ; Use the title of the window.

$iButSearchX = $aWPos[0] + $iButtonPosX
$iButSearchY = $aWPos[1] + $iButtonPosY

$iColor = PixelGetColor($iButSearchX, $iButSearchY)

MsgBox(0, "", "Normal Color: " & $iColor)

MouseMove($iButSearchX, $iButSearchY)

$iColor2 = PixelGetColor($iButSearchX, $iButSearchY)

MsgBox(0, "", "Normal Color: " & $iColor & "   Highlighted Color: " & $iColor2)


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...