Kevie Posted November 8, 2012 Share Posted November 8, 2012 I am trying to write a script to show my boss that what he is doing can be automated to save him time, so im attempting to make a test to demonstrate that. I want it to search the same area for 4-5 different images then once it finds one, click on it, then wait until it finds another of the images to click on. The problem arises once it finds its first match, that one image then becomes the only one it is looking for and it will ignore all of the rest of the image files I have. expandcollapse popup;Includes #include ;Variables Global $x1 = 0 Global $y1 = 0 Global $bmploc = @ScriptDir & "\Images\" Global $script = 0 ;Hotkeys HotKeySet("{F8}", "StartScript") ;Code While 1 While $script = 1 If _ImageSearchArea($bmploc & "test1.bmp", 1, 171, 350, 1281, 378, $x1, $y1, 0) Then MouseClick("left", $x1, $y1, 1, 5) MouseMove(1115, 364, 0) EndIf If _ImageSearchArea($bmploc & "test2.bmp", 1, 171, 350, 1281, 378, $x1, $y1, 0) Then MouseClick("left", $x1, $y1, 1, 5) MouseMove(1115, 364, 0) EndIf If _ImageSearchArea($bmploc & "test3.bmp", 1, 171, 350, 1281, 378, $x1, $y1, 0) Then MouseClick("left", $x1, $y1, 1, 5) MouseMove(1115, 364, 0) EndIf If _ImageSearchArea($bmploc & "test4.bmp", 1, 171, 350, 1281, 378, $x1, $y1, 0) Then MouseClick("left", $x1, $y1, 1, 5) MouseMove(1115, 364, 0) EndIf If _ImageSearchArea($bmploc & "test5.bmp", 1, 171, 350, 1281, 378, $x1, $y1, 0) Then MouseClick("left", $x1, $y1, 1, 5) MouseMove(1115, 364, 0) EndIf WEnd WEnd ;Functions Func StartScript() If $script = 0 Then $script = 1 ToolTip("Running|Press F8 to Stop", 200, 200, "Test", 1, 2) Sleep(2000) ToolTip("") Else $script = 0 ToolTip("Stopped|Press F8 to Start", 200, 200, "Test", 1, 2) Sleep(2000) ToolTip("") EndIf EndFunc So what am I missing here guys? Thanks for any help Link to comment Share on other sites More sharing options...
jmon Posted November 8, 2012 Share Posted November 8, 2012 On my computer what you are trying to do works well from what I understand. Are the images you are looking for changing all the time? Maybe you should post an image of the result you are looking for. I added a continueloop after the mousemove so when you find a match then start from top of loop again. Also put a sleep in your loop, otherwise your processor is going to get hot! Just a sleep(1) will reduce the cpu time a lot! [center]www.jmontserrat.comFile Sequence UDF - _StringExtractPaths - _StringTrimPattern - GuiCtrlSetOnTop - CalendarUDF[/center] Link to comment Share on other sites More sharing options...
Kevie Posted November 8, 2012 Author Share Posted November 8, 2012 Im very new to AutoIt yet, I have yet to use a continueloop before, and from the description in the help file I'm not 100% sure how I would implement in the script, but it does sound like that would solve my problems. Im not sure if the script is actually getting stuck on one image, or if it is just running through it slowly. It seemed to me like it was picking 2 of the images it "liked" and would always recognize those. But miss the others 75% of the time or so. Maybe its as simple as the script running slow on my machine? Link to comment Share on other sites More sharing options...
jmon Posted November 8, 2012 Share Posted November 8, 2012 (edited) what I was suggesting is this: ;Code While 1 While $script = 1 If _ImageSearchArea($bmploc & "test1.bmp", 1, 171, 350, 1281, 378, $x1, $y1, 0) Then MouseClick("left", $x1, $y1, 1, 5) MouseMove(1115, 364, 0) ContinueLoop EndIf If _ImageSearchArea($bmploc & "test2.bmp", 1, 171, 350, 1281, 378, $x1, $y1, 0) Then MouseClick("left", $x1, $y1, 1, 5) MouseMove(1115, 364, 0) ContinueLoop EndIf If _ImageSearchArea($bmploc & "test3.bmp", 1, 171, 350, 1281, 378, $x1, $y1, 0) Then MouseClick("left", $x1, $y1, 1, 5) MouseMove(1115, 364, 0) ContinueLoop EndIf If _ImageSearchArea($bmploc & "test4.bmp", 1, 171, 350, 1281, 378, $x1, $y1, 0) Then MouseClick("left", $x1, $y1, 1, 5) MouseMove(1115, 364, 0) ContinueLoop EndIf If _ImageSearchArea($bmploc & "test5.bmp", 1, 171, 350, 1281, 378, $x1, $y1, 0) Then MouseClick("left", $x1, $y1, 1, 5) MouseMove(1115, 364, 0) ContinueLoop EndIf Sleep(50) WEnd Sleep(50) WEnd The continueloop will continue from the top of the loop whenever one if is true. Now, I am not sure what this is what you are looking for. [EDIT] Nothing to do with your problem but you can simplify your script by doing a for loop: expandcollapse popup#include <imagesearch.au3> ;Variables Global $x1 = 0 Global $y1 = 0 Global $bmploc = @ScriptDir & "Images" Global $script = 0 Global $aSearch [4] = ["test1.bmp", "test2.bmp", "test3.bmp", "test4.bmp"] ;Hotkeys HotKeySet("{F8}", "StartScript") ;Code While 1 While $script = 1 For $i = 0 To UBound($aSearch) -1 If _ImageSearchArea($bmploc & $aSearch[$i], 1, 171, 350, 1281, 378, $x1, $y1, 0) Then MouseClick("left", $x1, $y1, 1, 5) MouseMove(1115, 364, 0) EndIf Next Sleep(150) WEnd Sleep(150) WEnd ;Functions Func StartScript() If $script = 0 Then $script = 1 ToolTip("Running|Press F8 to Stop", 200, 200, "Test", 1, 2) Sleep(2000) ToolTip("") Else $script = 0 EndIf EndFunc Edited November 8, 2012 by jmon [center]www.jmontserrat.comFile Sequence UDF - _StringExtractPaths - _StringTrimPattern - GuiCtrlSetOnTop - CalendarUDF[/center] Link to comment Share on other sites More sharing options...
Kevie Posted November 8, 2012 Author Share Posted November 8, 2012 (edited) Basically for this test I have my images scrolling down the right side of my screen, They always stop in the area I have defined by the ImageSearchArea func, once it clicks it it grays out so image search will no longer recognize it, then the mouse moves to the left then the scrolling continues, and it has to start looking for the set of images again until it finds another match. Ill give it a try and see what happens [EDIT] Thanks for that edit, I was wondering how to simplify that. I was going to try to figure that out once I had my issue figured out first hah Edited November 8, 2012 by Kevie Link to comment Share on other sites More sharing options...
jmon Posted November 8, 2012 Share Posted November 8, 2012 So do you mean that when you found a match, then you don't want to look for this image anymore? In that case you can try that. When an image is found, then delete it from the array of images: expandcollapse popup#include <imagesearch.au3> #include <Array.au3> ;Variables Global $x1 = 0 Global $y1 = 0 Global $bmploc = @ScriptDir & "\Images\" Global $script = 0 Global $aSearch [4] = ["test1.bmp", "test2.bmp", "test3.bmp", "test4.bmp"] ;Hotkeys HotKeySet("{F8}", "StartScript") ;Code While 1 While $script = 1 For $i = 0 To UBound($aSearch) -1 If _ImageSearchArea($bmploc & $aSearch[$i], 1, 171, 350, 1281, 378, $x1, $y1, 0) Then MouseClick("left", $x1, $y1, 1, 5) MouseMove(1115, 364, 0) ;when the image is found then remove it from the search array: _ArrayDelete($i) $i -= 1 EndIf Next Sleep(150) WEnd Sleep(150) WEnd ;Functions Func StartScript() If $script = 0 Then $script = 1 ToolTip("Running|Press F8 to Stop", 200, 200, "Test", 1, 2) Sleep(2000) ToolTip("") Else $script = 0 ToolTip("Stopped|Press F8 to Start", 200, 200, "Test", 1, 2) Sleep(2000) ToolTip("") EndIf EndFunc [center]www.jmontserrat.comFile Sequence UDF - _StringExtractPaths - _StringTrimPattern - GuiCtrlSetOnTop - CalendarUDF[/center] Link to comment Share on other sites More sharing options...
Kevie Posted November 8, 2012 Author Share Posted November 8, 2012 No the image will still need to be there, It could be possible that an image will show up multiple times through the operation Link to comment Share on other sites More sharing options...
jmon Posted November 8, 2012 Share Posted November 8, 2012 ok then in that case, I don't see why the previous post don't work... Maybe check if your .bmp images are exactly like what you are looking for? [center]www.jmontserrat.comFile Sequence UDF - _StringExtractPaths - _StringTrimPattern - GuiCtrlSetOnTop - CalendarUDF[/center] Link to comment Share on other sites More sharing options...
Kevie Posted November 8, 2012 Author Share Posted November 8, 2012 It must be a problem with the images. I just ran it for a couple mins. and it never missed image 1, missed image 2 once, only recognized image 3 once, and missed image 4 every time, I'll have to play around with it some more tomorrow when I get some time. Thanks for showing me how to clean it up an simplify it as well, that was definatly handy 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