Sign in to follow this  
Followers 0
Lempke

Pixelgetcolor

21 posts in this topic

#1 ·  Posted (edited)

I am trying to make a script that can execute several commands in a remote desktop. I already have a working script, but I had to put in some Sleep() to slow it down and wait for the screen to built. The problem that I encounter is that sometimes the script is to fast and at other times the script is to slow.

Normally I would use the WinWaitActive() to check for that, but since this is a remote session the active window is always the same. I would like to find a way to check if a window is already acive and I thought about the PixelGetColor() option.

If somebody has a better option, please let me know. :think:

To make sure, that the window is active I have tried to check 2 pixels on the sceen. But it seems that it doesn't work. If onloy one is correct the script contineus. What did I do wrong?

While (16711680 <> PixelGetColor(71, 921)) And (255 <> PixelGetColor(350, 250))     
  sleep(500)
WEnd

MsgBox(0, "Test", "Colors matched")
Edited by Lempke

Share this post


Link to post
Share on other sites



Why don't you just send the script to the remote computer and execute it there?

Otherwise you can use PixelCheckSum to see if changes have been made (like a new window opening.)

Without looking at it closer, your script looks right to me.

Share this post


Link to post
Share on other sites

The remote computer is a server and I am connecting to 3 different servers with one script. Now I can do that with one script, then I would have to use 3 scripts.

But it 's the challange to make it work like this and learn to work with the options of AutoIt.

It seems that the AND option in the WHILE not works. It works more like an OR

Share this post


Link to post
Share on other sites

Can somebody help me how I can check two pixels before the script continues?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

While (PixelGetColor(x, y) == 0x000000) And (PixelGetColor(x2, y2) == 0x0000FF)
I think this is the opposite of what you want.

Edit:

Sorry, I guess I might have misunderstood that... Be sure if you're trying to get the color on their desktop (wonder what would happen if the desktop was arranged differently?) that your using correct PixelCoordMode that matches the coord mode you used to get the coords from the AutoInfo Tool.

If you want it to exit the loop when it's found a color then you can even do a Do/Until loop:

Do
  ;Whatever
Until (PixelGetColor(x, y) == 0x000000) And (PixelGetColor(x2, y2) == 0x0000FF)
This means that both instances have to be true for it to exit. Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

@SmOke_N:

It seems that the AND is not working properly. When I try this script with only pixel to check it works fine.

But I want to make sure that everything is fully started so therefor I want to chack an other pixel as well. When I test this script with the AND function, the script already continues when only ONE is correct. Instead he should wait until the other one also is correct.

I have tried this with MsPaint:

- I start MsPaint and check a pixel in the red square from the colors at the bottom.

- The other check is a pixel in the drawing area.

- When Paint is started this is white and I want to check for bleu.

- So only when I fill the drawing area with the bleu color it should contineu...but the script continues before I put the bleu in.

When I only use the check in the drawing area it works fine.

What is the problem here???? The AND seems to work like an OR and that is not what I want. A bug??? Not possible like this???? Do I have to make two seperate Whiles???

Share this post


Link to post
Share on other sites

AND Definately does not work like OR. It's more than likely the way you've coded it (which we've not seen nor can we test I'm sure). Again, you may want to look at what I said about PixelCoordMode and AutoInfo Coord Mode.

But to humor you, replace the x / y - x2 / y2 and the 0x000000 and 0x0000FF with the real coords and colors (no AND in this).

While 1
    If (PixelGetColor(x, y) == 0x000000) Then
        If (PixelGetColor(x2, y2) == 0x0000FF) Then ExitLoop
    ElseIf (PixelGetColor(x2, y2) == 0x0000FF) Then
        If (PixelGetColor(x, y) == 0x000000) Then ExitLoop
    EndIf
WEnd

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

@SmOke_N: Thx for the code, I am going to try it.

But I don't understand wat is wrong with mine. It seems that it should work like this or not?

Is it possible to use an AND in the While() ??

I know that AND is no OR, but it doesn't work in the script.

Edited by Lempke

Share this post


Link to post
Share on other sites

It does work when I do it like this. :think:

While(16711680 <> PixelGetColor(71, 921)) 
    While(255 <> PixelGetColor(350, 250))       
        sleep(500)
    WEnd
WEnd

MsgBox(0, "Test", "Colors matched")

Share this post


Link to post
Share on other sites

#10 ·  Posted

It does work when I do it like this. :think:

While(16711680 <> PixelGetColor(71, 921)) 
    While(255 <> PixelGetColor(350, 250))       
        sleep(500)
    WEnd
WEnd

MsgBox(0, "Test", "Colors matched")
How about like:
While ((16711680 <> PixelGetColor(71, 921)) AND (255 <> PixelGetColor(350, 250)))
WEnd
?

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

How about like:

While ((16711680 <> PixelGetColor(71, 921)) AND (255 <> PixelGetColor(350, 250)))

WEnd?

Never thought about that. Seems a possibility, gonna try it like that.

Thx SmOke_N

Edited by Lempke

Share this post


Link to post
Share on other sites

#12 ·  Posted

Sorry, but it doesn't work like that. The script still continues before the second pixelcolor is equal to the dec value.

The one with the two While() loops works fine.

I think maybe this is a bug :think:

Share this post


Link to post
Share on other sites

#13 ·  Posted

I don't know how the While checks the different options, but maybe it's having an issue calling the 2nd PixelGetColor(). My last attempt.

Dim $Color1 = 16711680, $Color2 = 255

While $Color1 = 16711680 AND $Color2 = 255
    $Color1 = PixelGetColor(71, 921)
    $Color2 = PixelGetColor(350, 250)
WEnd

Now keep in mind that if either one of those colors change, then it breaks the loop with an And, if you wanted it to keep going if one of the colors was true then you would use Or, but I'm sure you know that (just making sure).


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#14 ·  Posted

@SmOke_N

What I want to do is: When the two pixels match then break the loop, but only then.

If only one pixel is matched stay in the loop.

Therefor I thought about using the AND in the While() loop, but when I tested it like that it didn't work. But the code I wrote seems to be allright.

This works:

While(16711680 <> PixelGetColor(71, 921)) 
    While(255 <> PixelGetColor(350, 250))       
        sleep(500)
    WEnd
WEnd

MsgBox(0, "Test", "Colors matched")

This doesn't work, but I thought it would. Seem more logically to me as well:

While(16711680 <> PixelGetColor(71, 921)) AND While(255 <> PixelGetColor(350, 250))     
    sleep(500)
WEnd

MsgBox(0, "Test", "Colors matched")

Share this post


Link to post
Share on other sites

#15 ·  Posted

@SmOke_N

What I want to do is: When the two pixels match then break the loop, but only then.

If only one pixel is matched stay in the loop.

Therefor I thought about using the AND in the While() loop, but when I tested it like that it didn't work. But the code I wrote seems to be allright.

This works:

While(16711680 <> PixelGetColor(71, 921)) 
    While(255 <> PixelGetColor(350, 250))       
        sleep(500)
    WEnd
WEnd

MsgBox(0, "Test", "Colors matched")

This doesn't work, but I thought it would. Seem more logically to me as well:

While(16711680 <> PixelGetColor(71, 921)) AND While(255 <> PixelGetColor(350, 250))     
    sleep(500)
WEnd

MsgBox(0, "Test", "Colors matched")
I guess I am to tired to comprehend the logic myself. How I see it now, is as soon as one of those conditions become untrue, the loop will break. While Condtion 1 And Condition 2 are True, as soon as one becomes un-true... poof, I suppose.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

have you tried something like this, might be easier

While 1

If 16711680 = PixelGetColor(71, 921) And 255 = PixelGetColor(350, 250) Then
            ExitLoop
EndIf

WEnd

EDIT: the above code worked for me, changed type in code

also, are you sure you have the colors exactly right? maybe using a pixel checksum would allow a little room for error in the colors...?

Edited by Don N

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Share this post


Link to post
Share on other sites

#17 ·  Posted

have you tried something like this, might be easier

While 1

If 16711680 = PixelGetColor(71, 921) And 255 = PixelGetColor(350, 250) Then
            ExitLoop
EndIf

WEnd

EDIT: the above code worked for me, changed type in code

also, are you sure you have the colors exactly right? maybe using a pixel checksum would allow a little room for error in the colors...?

Yes, that was explained that that does work.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#18 ·  Posted

@smoke_n

ooops, missed ur post on other page.... :">

@lempke

i ran ur code on my computer with an active remote desktop session, all i did was changed the colors and coords to fit my specs here and it worked perfectly. The only thing i coudl think of is that the colors are off. Does the script continue if only the second color is matched?


_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

"What I want to do is: When the two pixels match then break the loop, but only then.

If only one pixel is matched stay in the loop."

This will work:

While ((PixelGetColor (71, 921) <> 16711680) Or (PixelGetColor (350, 250) <> 255))
    Sleep (500)
WEnd

This will also work (they are essentially the same thing):

Do
    Sleep (500)
Until ((PixelGetColor (71, 921) = 16711680) And (PixelGetColor (350, 250) = 255))

The reason they work:

While:

1st case - neither pixel matches: since you want the loop to continue, one or the other needs to be true. Both are true, so it continues.

2nd case - first pixel matches, second doesn't: you still want the loop to continue; the first case is false, but the second case is true. Since I used Or, the loop will continue.

3rd case - first pixel doesn't match, second does: same as 2nd case, but other way around.

4th case - both match: you want the loop to stop. Since both will be false, the loop will stop. Success.

Do/Until:

This one is much more straightforward, since it says do this UNTIL both match. So, when both pixel match the checks, the loop stops.

Edit - forgot to finish.

Another point:

The reason the "While this and that" acts like an OR is because it is. What you're saying is that while both this and that are true, continue the loop. Another way of putting it is "if this or that is false, break the loop". You happen to be checking for negatives (if pixel is not color), so it got confusing.

Edited by greenmachine

Share this post


Link to post
Share on other sites

#20 ·  Posted

@smoke_n

ooops, missed ur post on other page.... :">

@lempke

i ran ur code on my computer with an active remote desktop session, all i did was changed the colors and coords to fit my specs here and it worked perfectly. The only thing i coudl think of is that the colors are off. Does the script continue if only the second color is matched?

The colors aren't off. I used the AutoIt Window Info tool to determine the pixel color and I have tried the script with only one of the arguments. (tried them both of course)

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  
Followers 0