Jump to content

ImageSearch.au3 help


Recommended Posts

Let me start by saying thanks for any help.

I'm using a library I downloaded (both have been attached)  to make a image finding program, upon finding the image I want to program to click to image. I have everything set up the way I want it I just need some help making the code less redundant and/or more efficient . I am also uploading my code.

 

I know it looks like crap, i'm very new to coding, thought I would start off with this scripting lang as it is very powerful and easy to use/learn.

ImageSearch.au3

ImageSearchDLL.dll

help me.au3

Link to comment
Share on other sites

im new too so hopefully this is correct :)

 

When you start your script you should setup your variables and reference your ImageSearch.au3

 

#include <ImageSearch.au3>

$x1=0
$y1=0

When your script finds the image it will assign coordinates to it using those variables

Inside the same function you can call on those variables and direct your mouse to MouseMove and or MouseClick

So since you want to open the image

Mouseclick("left",$x1,$y1,2)

 

 

Heres a pretty simple if then else you can pick apart and learn from

 

#include <ImageSearch.au3>

$x1=0
$y1=0

$result = _ImageSearch("test.png",1,$x1,$y1,0)
if $result=1 Then
    MouseMove($x1,$y1,3)
    Mouseclick("left",$x1,$y1,3)
Else
    MsgBox(0,"Not Found","Image not found...")
EndIf

Link to comment
Share on other sites

Yes I uploaded my script called help me, I'm wanting he'll optimizing that. Basically for each image I am making a new variable for that image, which is fine but I'm going to have about 200+ images by the end of this script so it's going to get very messy doing it like. So any advice on how I can shorten my code like maybe using an Array or something?

Link to comment
Share on other sites

I'm going to ask a very basic question and I'm looking at it from an audit point of view - not your task.

Does the image you are searching for represent a control? In other words - you say you want to click the image when found. What happens when this image is clicked?  A specific answer would be nice here.

IF there are many possible answers to my question - maybe a better way to do this is simply reply with a screenshot of the application you are trying to automate with a call out of the image you are wanting to find.

I'm asking this for the simple reason image searching is the WORST way to automate. There are many better ways to solve your problem.
--------------

Edit: seeing you are new, let me make one thing perfectly clear - if this is for a game, then please understand, this thread WILL be locked. If you are evasive in your responses - a mod will be alerted and further investigation on your intent will be asked. The reason for this is Game automation is NOT allowed to be discussed here in the AutoIt forum. (forum rules) No passing go, no $200. Now if you are doing something elese that is within the rules of the place, we are happy to help.

Edited by Bert
Link to comment
Share on other sites

You can do something like this:

#include <ImageSearch.au3>
#include <File.au3>
#include <GDIPlus.au3>
#include <Array.au3> ;just For debug


Local $aFiles = _FileListToArray(@ScriptDir & "\Pics\", "*.png", 1, True) ;add your pictures in a folder
If @error Then Exit
_ArrayDisplay($aFiles) ;debug files
; Initialize GDI+ library
_GDIPlus_Startup()


Local $aBitmaps[$aFiles[0]]
Local $hImage = 0

For $i = 0 To UBound($aBitmaps) - 1
    $hImage = _GDIPlus_ImageLoadFromFile($aFiles[$i + 1])
    $aBitmaps[$i] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _GDIPlus_ImageDispose($hImage) ;Clean up resources
Next


Local $iX = 0
Local $iY = 0
Local $iResult = 0
For $i = 0 To UBound($aBitmaps) - 1
    $iResult = _ImageSearch($aBitmaps[$i], 1, $iX, $iY, 20, 0)
    If $iResult Then
        MouseMove($iX, $iY)
        MouseClick("Left", $iX, $iY, 2)
    Else
        MsgBox(1, "Error", "Could not find image")
    EndIf
Next


;release the resources
For $i = 0 To UBound($aBitmaps) - 1
    _WinAPI_DeleteObject($aBitmaps[$i])
Next


; Shut down GDI+ library
_GDIPlus_Shutdown()

 

Saludos

Edited by Danyfirex
Link to comment
Share on other sites

1 hour ago, Danyfirex said:

You can do something like this:

#include <ImageSearch.au3>
#include <File.au3>
#include <GDIPlus.au3>
#include <Array.au3> ;just For debug


Local $aFiles = _FileListToArray(@ScriptDir & "\Pics\", "*.png", 1, True) ;add your pictures in a folder
If @error Then Exit
_ArrayDisplay($aFiles) ;debug files
; Initialize GDI+ library
_GDIPlus_Startup()


Local $aBitmaps[$aFiles[0]]
Local $hImage = 0

For $i = 0 To UBound($aBitmaps) - 1
    $hImage = _GDIPlus_ImageLoadFromFile($aFiles[$i + 1])
    $aBitmaps[$i] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _GDIPlus_ImageDispose($hImage) ;Clean up resources
Next


Local $iX = 0
Local $iY = 0
Local $iResult = 0
For $i = 0 To UBound($aBitmaps) - 1
    $iResult = _ImageSearch($aBitmaps[$i], 1, $iX, $iY, 20, 0)
    If $iResult Then
        MouseMove($iX, $iY)
        MouseClick("Left", $iX, $iY, 2)
    Else
        MsgBox(1, "Error", "Could not find image")
    EndIf
Next


;release the resources
For $i = 0 To UBound($aBitmaps) - 1
    _WinAPI_DeleteObject($aBitmaps[$i])
Next


; Shut down GDI+ library
_GDIPlus_Shutdown()

 

Saludos

Thank you that was what I needed :)

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
 Share

  • Recently Browsing   0 members

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