AZPERRY Posted November 4, 2019 Share Posted November 4, 2019 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 Link to comment Share on other sites More sharing options...
water Posted November 4, 2019 Share Posted November 4, 2019 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: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
AZPERRY Posted November 4, 2019 Author Share Posted November 4, 2019 Just a simple click on a image. It compiles. But doesnt execute.. Says invalid function Link to comment Share on other sites More sharing options...
TheSaint Posted November 4, 2019 Share Posted November 4, 2019 (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 November 4, 2019 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. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. 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) Link to comment Share on other sites More sharing options...
TheXman Posted November 4, 2019 Share Posted November 4, 2019 (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 November 4, 2019 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Nine Posted November 4, 2019 Share Posted November 4, 2019 (edited) Run it in Scite, you will see plenty of errors in your code... Put Opt ("MustDeclareVars", 1) at the top of your script after #include Edited November 4, 2019 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Zedna Posted November 4, 2019 Share Posted November 4, 2019 Change HotKeySet("{ESC}", "Exit") to HotKeySet("{ESC}", "MyExit") Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
AZPERRY Posted November 4, 2019 Author Share Posted November 4, 2019 (3) : ==> Unknown function name.: include <ImageSearch.au3> ^ ERROR >Exit code: 1 Time: 0.1013 Link to comment Share on other sites More sharing options...
water Posted November 4, 2019 Share Posted November 4, 2019 Needs to be #include <ImageSearch.au3> My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
AZPERRY Posted November 4, 2019 Author Share Posted November 4, 2019 #include <ImageSearch.au3> that gives me same error but with the # ? Link to comment Share on other sites More sharing options...
water Posted November 4, 2019 Share Posted November 4, 2019 Where did you store the file ImageSearch.au3? Same directory as your script? User defind include directory? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
AZPERRY Posted November 4, 2019 Author Share Posted November 4, 2019 In the same location as script. Link to comment Share on other sites More sharing options...
Zedna Posted November 4, 2019 Share Posted November 4, 2019 Then use #include "ImageSearch.au3" Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
AZPERRY Posted November 4, 2019 Author Share Posted November 4, 2019 #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 Link to comment Share on other sites More sharing options...
Musashi Posted November 4, 2019 Share Posted November 4, 2019 14 minutes ago, AZPERRY said: $pump = _ImageSearch("pump.png",1,$x1,$y1,0)? Remove the ? at the end of the line. Don't know why, but sometimes this happens when you C&P Code from the forum. "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
AZPERRY Posted November 4, 2019 Author Share Posted November 4, 2019 still same error 😐 Link to comment Share on other sites More sharing options...
water Posted November 4, 2019 Share Posted November 4, 2019 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: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted November 4, 2019 Share Posted November 4, 2019 3 hours ago, Musashi said: Don't know why, but sometimes this happens when you C&P Code from the forum. If you're interested Musashi 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Musashi Posted November 4, 2019 Share Posted November 4, 2019 (edited) 2 hours ago, 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! 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 : Spoiler expandcollapse popup#include-once ; ------------------------------------------------------------------------------ ; ; AutoIt Version: 3.0 ; Language: English ; Description: Functions that assist with Image Search ; Require that the ImageSearchDLL.dll be loadable ; ; ------------------------------------------------------------------------------ ;=============================================================================== ; ; Description: Find the position of an image on the desktop ; Syntax: _ImageSearchArea, _ImageSearch ; Parameter(s): ; $findImage - the image to locate on the desktop ; $tolerance - 0 for no tolerance (0-255). Needed when colors of ; image differ from desktop. e.g GIF ; $resultPosition - Set where the returned x,y location of the image is. ; 1 for centre of image, 0 for top left of image ; $x $y - Return the x and y location of the image ; ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 ; ; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify ; a desktop region to search ; ;=============================================================================== Func _ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance, $HBMP=0) return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance,$HBMP) EndFunc Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance,$HBMP=0) ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom) if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage If IsString($findImage) Then $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage,"ptr",$HBMP) Else $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"ptr",$findImage,"ptr",$HBMP) EndIf ; If error exit if $result[0]="0" then return 0 ; Otherwise get the x,y location of the match and the size of the image to ; compute the centre of search $array = StringSplit($result[0],"|") $x=Int(Number($array[2])) $y=Int(Number($array[3])) if $resultPosition=1 then $x=$x + Int(Number($array[4])/2) $y=$y + Int(Number($array[5])/2) endif return 1 EndFunc ;=============================================================================== ; ; Description: Wait for a specified number of seconds for an image to appear ; ; Syntax: _WaitForImageSearch, _WaitForImagesSearch ; Parameter(s): ; $waitSecs - seconds to try and find the image ; $findImage - the image to locate on the desktop ; $tolerance - 0 for no tolerance (0-255). Needed when colors of ; image differ from desktop. e.g GIF ; $resultPosition - Set where the returned x,y location of the image is. ; 1 for centre of image, 0 for top left of image ; $x $y - Return the x and y location of the image ; ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 ; ; ;=============================================================================== Func _WaitForImageSearch($findImage,$waitSecs,$resultPosition,ByRef $x, ByRef $y,$tolerance,$HBMP=0) $waitSecs = $waitSecs * 1000 $startTime=TimerInit() While TimerDiff($startTime) < $waitSecs sleep(100) $result=_ImageSearch($findImage,$resultPosition,$x, $y,$tolerance,$HBMP) if $result > 0 Then return 1 EndIf WEnd return 0 EndFunc ;=============================================================================== ; ; Description: Wait for a specified number of seconds for any of a set of ; images to appear ; ; Syntax: _WaitForImagesSearch ; Parameter(s): ; $waitSecs - seconds to try and find the image ; $findImage - the ARRAY of images to locate on the desktop ; - ARRAY[0] is set to the number of images to loop through ; ARRAY[1] is the first image ; $tolerance - 0 for no tolerance (0-255). Needed when colors of ; image differ from desktop. e.g GIF ; $resultPosition - Set where the returned x,y location of the image is. ; 1 for centre of image, 0 for top left of image ; $x $y - Return the x and y location of the image ; ; Return Value(s): On Success - Returns the index of the successful find ; On Failure - Returns 0 ; ; ;=============================================================================== Func _WaitForImagesSearch($findImage,$waitSecs,$resultPosition,ByRef $x, ByRef $y,$tolerance,$HBMP=0) $waitSecs = $waitSecs * 1000 $startTime=TimerInit() While TimerDiff($startTime) < $waitSecs for $i = 1 to $findImage[0] sleep(100) $result=_ImageSearch($findImage[$i],$resultPosition,$x, $y,$tolerance,$HBMP) if $result > 0 Then return $i EndIf Next WEnd return 0 EndFunc 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 November 4, 2019 by Musashi "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
AZPERRY Posted November 5, 2019 Author Share Posted November 5, 2019 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now