Jump to content

PixelGetColor Issue with pop-up box


 Share

Recommended Posts

So I am creating a script for automating a java application. One part of the script continuously scrolls up until the screen changes, finding a certain pixel changed to a certain color. However, during the scrolling, there is the chance that a popup box (within the application's interface) might come up. If it does, it has a big blue button that is one of two shades of blue. So, in the While loop, I also check to see if that certain pixel is the blue color, because it would never be otherwise if the popup box did not appear.

The loop will successfully terminate the scrolling if it gets to the point where the screen changes, but it completely ignores when the popup box appears. If the popup box appears, it continues to try to press up, even though the popup freezes the screen. Oddly enough, if I terminate the script and rerun it while the popup box is already there, it will successfully see the blue colored button and click the popup box.

I am going to post the top of the While loop in question, so you can see what I mean. The second ExitLoop line is the one that does not function and causes the script to keep pressing up, unless I restart the script with the popup box already there.

While 1
If PixelGetColor(945, 549) = 0xD8C0A0 Then ExitLoop
If PixelGetColor(1307, 525) = 0x527DC5 Or PixelGetColor(1307, 525) = 0x729BDF Then ExitLoop
Send("{DOWN DOWN}")
Sleep(210)
Send("{DOWN UP}")

Also, it may seem silly the way I am holding the up arrow each loop, but it makes sense with my application.

I have been struggling with this for hours, and cannot figure out why it is not detecting this box and the blue button when it pops up. Any help is greatly appreciated!

Edited by eagle132
Link to comment
Share on other sites

why arent all PixelGetColor's all in one If statement??

you could be getting stuck with the first If statement. you also might wanna let us know what you specifically r trying to do so we can help

Hi sorry I'm very new to AutoIT, this is my first script. Originally they were, and it still did not work, I split it just out of inexperience with the language to see if there was something I was missing.

Its basically a java app that I am using for work that has a scrolling feature and there are certain areas that change color while its scrolling. When a popup box appears, I need the script to be able to detect it as it is looping through and scrolling and click the button to close the popup. I wish I could describe it in more detail in that but because it is not a public application I cannot give a ton of detail. Hopefully someone has a suggestion as to why its not working?

Another thing I noticed today was that if the script is running and the popup appears, and open up a new window and cover up the button with it on my screen, then drag it away (effectively changing the color from and then back to the blue color on my screen), the script will then see the change in color and kill the loop. Very weird.

Link to comment
Share on other sites

Since it is your first script, a full post of the entire thing may be in order so we could take a look at it and give pointers on the debugging. As it stands right now ... the snippet is a little lacking without context.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

Since it is your first script, a full post of the entire thing may be in order so we could take a look at it and give pointers on the debugging. As it stands right now ... the snippet is a little lacking without context.

Probably a good idea. Here it is in all it's simplicity, don't laugh I'm new!

HotKeySet("p", "test")
HotKeySet("{ESC}", "TogglePause")

Func TogglePause()
    $menu = MsgBox(4, "Menu", "Are you sure you want to terminate the script?")
     If $menu = 6 Then
         Exit
     EndIf
 EndFunc
 Func test()
    MsgBox(0, "Test", "The pixel color at 1289, 531 is " & PixelGetColor(1289, 531))
 EndFunc

WinActivate ( "Changed for privacy" )

While 1    
    While 1
        If PixelGetColor(945, 549) = 0xD8C0A0 Or PixelGetColor(1307, 525) = 0x527DC5 Or PixelGetColor(1307, 525) = 0x729BDF Then ExitLoop
        Send("{DOWN DOWN}")
        Sleep(210)
        Send("{DOWN UP}")
    WEnd
    If PixelGetColor(928, 520) = 0xE0E8E8 And PixelGetColor(928, 460) = 0xF86848 Then
        Local $popupGone = 0xFFFFFF
        While $popupGone <> 0x000000
            MouseClick("left", 1264, 522, 1)
            $popupGone = PixelGetColor(1566, 195)
        WEnd
    EndIf
WEnd

In the while loop, the first pixel in the ExitLoop statement is the one that it is finding properly when it scrolls to the proper color. The second two are for the button, which is one of those two colors, and it is not recognizing, as described in earlier posts. I changed the window name for privacy purposes. Also, the "test" function doesn't really help because it doesn't display the color properly. When the popup is gone, the screen turns to black in the area that I search for the pixel, so the mouse should just keep clicking the button until the popup is gone.

Thanks!

Edited by eagle132
Link to comment
Share on other sites

I ran into similar issues working with an AS400 emulator. Very stubborn and could really only brute force it like you are with this java window.

Edit: Hold on, analyzing code again.

Best I could do to help was add debugging statments to it. Your code looks sound to me. Since I don't have the program you are trying to interact with, this is about as much as I can offer.

HotKeySet("p", "test")
HotKeySet("{ESC}", "TogglePause")

Func TogglePause()
    $menu = MsgBox(4, "Menu", "Are you sure you want to terminate the script?")
    If $menu = 6 Then
        Exit
    EndIf
EndFunc   ;==>TogglePause

Func test()
    MsgBox(0, "Test", "The pixel color at 1289, 531 is " & PixelGetColor(1289, 531))
EndFunc   ;==>test

WinActivate("Changed for privacy")

While 1
    Sleep(10)
    ConsoleWrite("Entered first while loop" & @CRLF)
    
    While 1
        ConsoleWrite("Entered second while loop" & @CRLF)
        If PixelGetColor(945, 549) = 0xD8C0A0 Or PixelGetColor(1307, 525) = 0x527DC5 Or PixelGetColor(1307, 525) = 0x729BDF Then ExitLoop
        Send("{DOWN DOWN}")
        Sleep(210)
        Send("{DOWN UP}")
    WEnd
    
    ConsoleWrite("Found something and exited loop" & @CRLF)
    
    If PixelGetColor(928, 520) = 0xE0E8E8 And PixelGetColor(928, 460) = 0xF86848 Then
        ConsoleWrite("Found something and entered third while loop" & @CRLF)
        $popupGone = 0xFFFFFF
        While $popupGone <> 0x000000
            Sleep(10)
            MouseClick("left", 1264, 522, 1)
            $popupGone = PixelGetColor(1566, 195)
        WEnd
    EndIf
    
WEnd
Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

this is how i would implement it:

HotKeySet("p", "test")
HotKeySet("{ESC}", "TogglePause")

Func TogglePause()
    $menu = MsgBox(4, "Menu", "Are you sure you want to terminate the script?")
     If $menu = 6 Then
         Exit
     EndIf
 EndFunc
 Func test()
    MsgBox(0, "Test", "The pixel color at 1289, 531 is " & PixelGetColor(1289, 531))
 EndFunc

WinActivate ( "Changed for privacy" )

While 1    
    While PixelGetColor(945, 549) <> 0xD8C0A0 Or PixelGetColor(1307, 525) <> 0x527DC5 Or PixelGetColor(1307, 525) <> 0x729BDF
        Send("{DOWN DOWN}")
        Sleep(210)
        Send("{DOWN UP}")
    WEnd
    ConsoleWrite("Exited While Loop" & @CRLF)
    If PixelGetColor(928, 520) = 0xE0E8E8 And PixelGetColor(928, 460) = 0xF86848 Then
        Local $popupGone = 0xFFFFFF
        While $popupGone <> 0x000000
            MouseClick("left", 1264, 522, 1)
            $popupGone = PixelGetColor(1566, 195)
            ConsoleWrite("$popupGone: " & $popupGone & @CRLF)
        WEnd
    Else
        ConsoleWrite("If statement came back false. Entering the While again." & @CRLF)
    EndIf
WEnd
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...