Guest Cannibal Posted January 12, 2005 Share Posted January 12, 2005 I'm trying to write a macro and I'm wondering if I can search an area for multiple colours (10 actually) For e.g: Scan for 'red' if yes then click somewhere, if no scan for 'green' if yes click somewhere, if no scan for 'blue' if yes click somewhere, if no click somewhere else. I'll add what I have done so far, but its not working: expandcollapse popupWinWaitActive("Shimlar - Microsoft Internet Explorer") While 1 PixelSearch ( 493, 262, 691, 283, 0x00FF50, 1 ) If Not @error Then Sleep(4500) MouseClick("left", 544, 271 ) Else MouseClick("left", 780, 168 ) Sleep(2000) PixelSearch ( 518, 208, 821, 825, 0xD098B0, 1 ) If Not @error Then Sleep(4500) MouseClick("left", 780, 168 ) Else PixelSearch ( 518, 208, 821, 825, 0x0085EC, 1 ) If Not @error Then Sleep(4500) MouseClick("left", 780, 168 ) Else PixelSearch ( 518, 208, 821, 825, 0xB5B3B3, 1 ) If Not @error Then Sleep(4500) MouseClick("left", 780, 168 ) Else PixelSearch ( 518, 208, 821, 825, 0x22AC53, 1 ) If Not @error Then Sleep(4500) MouseClick("left", 780, 168 ) Else PixelSearch ( 518, 208, 821, 825, 0xC0FFFF, 1 ) If Not @error Then Sleep(4500) MouseClick("left", 780, 168 ) Else PixelSearch ( 518, 208, 821, 825, 0x43F0FF, 1 ) If Not @error Then Sleep(4500) MouseClick("left", 780, 168 ) Else PixelSearch ( 518, 208, 821, 825, 0xFF3737, 1 ) If Not @error Then Sleep(4500) MouseClick("left", 780, 168 ) Else PixelSearch ( 518, 208, 821, 825, 0xFF8965, 1 ) If Not @error Then Sleep(4500) MouseClick("left", 780, 168 ) Else PixelSearch ( 518, 208, 821, 825, 0x03AF03, 1 ) If Not @error Then Sleep(4500) MouseClick("left", 780, 168 ) Else PixelSearch ( 518, 208, 821, 825, 0xD4D0C8, 1 ) If Not @error Then Sleep(4500) MouseClick("left", 780, 168 ) Else MouseClick("left", 780, 168 ) Sleep(5500) MouseClick("left", 594, 195 ) Sleep(5500) EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf WEnd As you can tell I havn't coded before so its pretty sloppy. Link to comment Share on other sites More sharing options...
b14ck Posted January 12, 2005 Share Posted January 12, 2005 1 endif -I am the giver of life and the bringer of death. Link to comment Share on other sites More sharing options...
Guest Cannibal Posted January 12, 2005 Share Posted January 12, 2005 (edited) "AutoIt Error: "Line 98 WEnd Error: "Wend statment with no matching "While statement." Still doesn't work... It doesn't even open anymore Edited January 12, 2005 by Cannibal Link to comment Share on other sites More sharing options...
Wolvereness Posted January 12, 2005 Share Posted January 12, 2005 A more tidy version:expandcollapse popupWinWaitActive("Shimlar - Microsoft Internet Explorer") While 1 PixelSearch (493, 262, 691, 283, 0x00FF50, 1) If Not @error Then Sleep(4500) MouseClick("left", 544, 271) ContinueLoop EndIf MouseClick("left", 780, 168) Sleep(2000) PixelSearch (518, 208, 821, 825, 0xD098B0, 1) If Not @error Then Sleep(4500) MouseClick("left", 780, 168) ContinueLoop EndIf PixelSearch(518, 208, 821, 825, 0x0085EC, 1) If Not @error Then Sleep(4500) MouseClick("left", 780, 168) ContinueLoop EndIf PixelSearch(518, 208, 821, 825, 0xB5B3B3, 1) If Not @error Then Sleep(4500) MouseClick("left", 780, 168) ContinueLoop EndIf PixelSearch(518, 208, 821, 825, 0x22AC53, 1) If Not @error Then Sleep(4500) MouseClick("left", 780, 168) ContinueLoop EndIf PixelSearch(518, 208, 821, 825, 0xC0FFFF, 1) If Not @error Then Sleep(4500) MouseClick("left", 780, 168) ContinueLoop EndIf PixelSearch(518, 208, 821, 825, 0x43F0FF, 1) If Not @error Then Sleep(4500) MouseClick("left", 780, 168) ContinueLoop EndIf PixelSearch(518, 208, 821, 825, 0xFF3737, 1) If Not @error Then Sleep(4500) MouseClick("left", 780, 168) ContinueLoop EndIf PixelSearch(518, 208, 821, 825, 0xFF8965, 1) If Not @error Then Sleep(4500) MouseClick("left", 780, 168) ContinueLoop EndIf PixelSearch(518, 208, 821, 825, 0x03AF03, 1) If Not @error Then Sleep(4500) MouseClick("left", 780, 168) ContinueLoop EndIf PixelSearch(518, 208, 821, 825, 0xD4D0C8, 1) If Not @error Then Sleep(4500) MouseClick("left", 780, 168) ContinueLoop EndIf MouseClick("left", 780, 168) Sleep(5500) MouseClick("left", 594, 195) Sleep(5500) WEnd Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote] Link to comment Share on other sites More sharing options...
Guest Cannibal Posted January 12, 2005 Share Posted January 12, 2005 Thanks, that one worked fine. I also had to allow for more colour shades. So I think that was a major problem too. But it all works now, thanks alot Link to comment Share on other sites More sharing options...
Bartokv Posted January 12, 2005 Share Posted January 12, 2005 I'm not sure why you'd want the script to never end, but since most of the code is repetative I'd probably do something like the following: Dim $colors = StringSplit("D098B0,0085EC,B5B3B3,22AC53,C0FFFF,43F0FF,FF3737,FF8965,03AF03,D4D0C8",",") Dim $flag = 0 WinWaitActive("Shimlar - Microsoft Internet Explorer") While 1; This routine will never end... PixelSearch ( 493, 262, 691, 283, 0x00FF50, 1 ) If Not @error Then Sleep(4500) MouseClick("left", 544, 271 ) $flag = 1 Else MouseClick("left", 780, 168 ) Sleep(2000) For $i = 1 to (ubound($colors) - 1) PixelSearch ( 518, 208, 821, 825, 0x & $colors[$i], 1 ) If Not @error Then $flag = 1 ExitLoop Else Sleep(100) EndIf Next EndIf If ($flag = 1) Then Sleep(4500) MouseClick("left", 780, 168 ) Sleep(5500) MouseClick("left", 594, 195 ) $flag = 0 EndIf WEnd You could also place all of the search colors/areas within different arrays and make the code even more compact. Please keep in mind that this code has not been tested, and I'm a little rusty with AutoIt script as of late. Hope this helps! 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