TwistedXion Posted July 11, 2017 Share Posted July 11, 2017 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 More sharing options...
Teckx Posted July 11, 2017 Share Posted July 11, 2017 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 More sharing options...
TwistedXion Posted July 11, 2017 Author Share Posted July 11, 2017 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 More sharing options...
Bert Posted July 11, 2017 Share Posted July 11, 2017 (edited) 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 July 11, 2017 by Bert The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Danyfirex Posted July 11, 2017 Share Posted July 11, 2017 (edited) You can do something like this: expandcollapse popup#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 July 11, 2017 by Danyfirex Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
TwistedXion Posted July 11, 2017 Author Share Posted July 11, 2017 1 hour ago, Danyfirex said: You can do something like this: expandcollapse popup#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 More sharing options...
TwistedXion Posted July 11, 2017 Author Share Posted July 11, 2017 @Bert no its not for a game. I'm trying to find simular pictures on the Internet and download them (ones with the proper copyrights of course ) Link to comment Share on other sites More sharing options...
Bert Posted July 12, 2017 Share Posted July 12, 2017 22 hours ago, TwistedXion said: @Bert no its not for a game. I'm trying to find simular pictures on the Internet and download them (ones with the proper copyrights of course ) ok - i'm good with that The Vollatran project My blog: http://www.vollysinterestingshit.com/ 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