Jump to content

Recommended Posts

Posted

Hello there AutoIT users.

I have used Auto it but its been a few years and most my time is working on PLC logic controllers.

Can i ask what is wrong with my code here please?

HotKeySet("{ESC}", "Exit")

include <ImageSearch.au3>


Func MyExit()

    MsgBox(0, "Ending")
    Exit

EndFunc   ;==>MyExit

While 1
    _click()
WEnd


Func _click()

    ConsoleWrite("Starting search" & @CRLF)
    $pump = _ImageSearch('pump.png', 1, $x, $y, 100)

    if $pump True then
        ConsoleWrite("found pump!" & @CRLF)
        MouseClick("left", $pump)
        Sleep(100)
        EndIf
EndFunc

 

Posted

Please post what you expect it to do, what it does when you run your script, if you get any error messages ...

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (edited)

I am not familiar with either the _ImageSearch function or Include (UDF) file.

However, I recommend a Sleep of at least 100 in you While ... Wend loop, after _click()

So I don't know if you should be providing $x and $y coordinates, or they just get values returned to those variables. Or indeed whether 'pump.png' is meant to be a full path, or what the 100 parameter is for, or for that matter the 1. I am presuming $pump is a returned coordinate.

Like water says, what is expected from your code?

When providing code, you should Quote it and select AutoIt code, like so. Makes it easier for us to work with.

HotKeySet("{ESC}", "Exit")

include <ImageSearch.au3>


Func MyExit()

    MsgBox(0, "Ending")
    Exit

EndFunc   ;==>MyExit

While 1
    _click()
WEnd


Func _click()

    ConsoleWrite("Starting search" & @CRLF)
    $pump = _ImageSearch('pump.png', 1, $x, $y, 100)

    if $pump True then
        ConsoleWrite("found pump!" & @CRLF)
        MouseClick("left", $pump)
        Sleep(100)
        EndIf
EndFunc

 

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

  Reveal hidden contents

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted (edited)

Is this your whole script?  Where are the values for $x & $y coming from?

Edit:  Sorry, I must have hit enter at the same time as TheSaint, with the same question.

Edited by TheXman
Posted

Needs to be

#include <ImageSearch.au3>

 

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Where did you store the file ImageSearch.au3?
Same directory as your script? User defind include directory?

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted
#include "Image_Search.au3"

$x1=0
$y1=0

$pump = _ImageSearch("pump.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

ok im doing something wrong here as i cant even get this to work.........

$pump = _ImageSearch("pump.png",1,$x1,$y1,0)?
$pump = ^ ERROR
>Exit code: 1    Time: 0.104

 

Posted
  On 11/4/2019 at 4:02 PM, AZPERRY said:

$pump = _ImageSearch("pump.png",1,$x1,$y1,0)?

Expand  

Remove the ? at the end of the line. Don't know why, but sometimes this happens when you C&P Code from the forum.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Posted

You are sure your function starts with an underscore?
I searched the forum and found this. If this is the UDF you use then the function name does not start with an "_". If you use another image search library, then please open the UDF and check the name of the function!

; PUBLIC FUNCTIONS
func image_search($sign, $width, $height)
    Local $pos[2]
    Local $hp[2]
    $pos[0] = -1
    $pos[1] = -1
    $hp[0] = -1
    $hp[1] = -1
    $color = $sign[0]
    do
        $hp = next_screen_hotpoint($hp[1],$color)
        if $hp[1] <> -1 then
            $aux = $hp[1]
            do
                if verify_sign($sign,$width,$height,$hp[0],$hp[1]) then
                    $pos = getMiddlePoint($hp[0],$hp[1],$hp[0]+$width-1,$hp[1]+$height-1)
                    return $pos
                endif
                $hp = next_row_hotpoint($hp[0],$hp[1],$color)
            until $hp[1] == -1
            $hp[1] = $aux
        endif
    until $hp[1] == -1
    return $pos
endfunc

 

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (edited)
  On 11/4/2019 at 6:45 PM, water said:

You are sure your function starts with an underscore?
I searched the forum and found this. If this is the UDF you use then the function name does not start with an "_". If you use another image search library, then please open the UDF and check the name of the function!

Expand  

Hi @water

I'm pretty sure @AZPERRY uses  this UDF (not the one you have been linking to).

_ImageSearch is the correct function name, see :

  Reveal hidden contents

The UDF requires ImageSearchDLL.dll , which is included in the Zipfiles. In the thread, some users report bugs or have made modifications. Also see https://www.autoitscript.com/forum/topic/189338-imagesearchau3-help/

To be honest, I never had the desire (nor a reason) to work with ImageSearch . Maybe I would give it a try just for fun, but I'm not sure if I can trust the .dll.

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Posted

Right guy's i have  progressed.

My issue now is that it doesn't actually click on the image.

The image is just on the desktop.

HotKeySet("{ESC}", "MyExit")

#include "ImageSearch.au3"

Func MyExit()

    MsgBox(0, "Ending")
    Exit

EndFunc   ;==>MyExit

$x1=0
$y1=0

While 1
    _click()
 WEnd


Func _click()
$pump = "‪C:\Users\Perrya\Desktop\Autoit\pump.png"

$pump1 = _ImageSearch($pump,1,$x1,$y1,0,0)
    ConsoleWrite("Starting search" & @CRLF)

   if $pump1 = 1 then
      ConsoleWrite("found pump" & @CRLF)
      MouseClick($pump1)
      Sleep(100)
      EndIf
EndFunc

 

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...