Jump to content
Sign in to follow this  
Guest Cannibal

Multi PixelSearch

Recommended Posts

Guest Cannibal

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:

WinWaitActive("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.

Share this post


Link to post
Share on other sites
Guest Cannibal

"AutoIt Error:

"Line 98

WEnd

Error: "Wend statment with no matching "While statement."

Still doesn't work... It doesn't even open anymore

Edited by Cannibal

Share this post


Link to post
Share on other sites

A more tidy version:

WinWaitActive("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]

Share this post


Link to post
Share on other sites
Guest Cannibal

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 :idiot:

Share this post


Link to post
Share on other sites

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

Hope this helps!

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...