Sign in to follow this  
Followers 0
inmysights

Pixel color change

27 posts in this topic

I have been working on a script and it is almost done, except for one piece of it I cannot get the logic correct on, and was wondering if someone can push me in the right direction.

I have a pixel that is white and if it changes to green do something, seems very simple to do. I have tried 3 different ways to code it and all have failed.

I think the way I am getting and storing the pixel is wrong, I am using $var = PixelGetColor( 677, 685 ), which is 0xC6D2DD a white color. then I have a check to say if it is white, move mouse to that spot. I am using this as just a test to get it working.

If $var == "0xC6D2DD" Then

MouseClick("left", 677, 685)

EndIf

that should work, but the mouse does not move there. can I make the check like this, that they == each other? I have read through other examples and tried google, I am trying to find where my logic is going wrong, but for the life of me cannot.

Thank you for any help.

Share this post


Link to post
Share on other sites



Try this. Change

If $var == "0xC6D2DD" Then

To

If $var = 0xC6D2DD Then

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

I changed it and it still doesn't work.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Run this

$var = PixelGetColor(677, 685)
 MsgBox(0,"The hex color is", Hex($var, 6))
Edited by snowmaker

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

I ran that, to double check the color with the au3 utility and that is how I got the color I needed to use, I also used the mouseclix utility found on these forums, so I know from 3 sources that the hex color is correct.

Share this post


Link to post
Share on other sites

after that I have this:

If $var == 0xC6D2DD Then

MouseClick("left", 677, 685)

EndIf

Share this post


Link to post
Share on other sites

actually I changed it to

If $var = 0xC6D2DD Then

MouseClick("left", 677, 685)

EndIf

Share this post


Link to post
Share on other sites

If this still isnt working, you might need to add this line to the top of your script. Change the value as needed.

Opt("PixelCoordMode", 1)        ;1=absolute, 0=relative, 2=client

Because PixelGetColor returns a decimal value, and you were checking against a hex value, I wrote this (well mostly copy/paste >_< ) to see if that cause a problem

$var = PixelGetColor( 120, 160 ) ;$var is decimal value
;MsgBox(0,"The color is", $var)
If $var = 0xc0c0c0 Then          ;but matches with equiv hex value
MouseClick("left", 20, 780)
EndIf

It gets the pixel color and if it's silver, clicks once on my start button.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

AHHH, ok, ok, I know what the problem is now that you showed me that!

it was working but it was immediately clicking right after I did the mouse drag in a place that it didn't need to be. So what I need to do is change it so that this happens, wait for this pixel that is now white to change when it turns green.

Posted Image

Posted Image

what I want to do is see the before pic, as soon as that green line crosses the white line(green line from after pic),left click, I need to wait till it goes all the way from let to right across that line and left click, I was left clicking as soon as it started to go left.

Which was no good!

I am guessing I need to loop and keep checking till it reaches there? or how do I make it keep checking that pixel till it changes color? I am thinking and not coming up with anything.

thank you!

Share this post


Link to post
Share on other sites

I am guessing I need to loop and keep checking till it reaches there? or how do I make it keep checking that pixel till it changes color?

Maybe a Keyword Do...Until loop?


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

that just keeps pressing left mouse, over and over, logic is almost there but it needs to click left as soon as it changes.

Share this post


Link to post
Share on other sites

I would use the loop to do just the checking, IOW, put the click statement after the loop (not in the loop)


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

damn, I thought we had it, seriously thought that was going to work!! it still just goes right on through the white line and no click.

Share this post


Link to post
Share on other sites

How about trying with Function PixelChecksum, and/or instead of checking if/when the white line changes, check if/when the area just after the white line changes?


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Here it what I have so far:

;UDF= user defined function

#include <Misc.au3>

;set the escape button to the exit function

HotKeySet("{esc}", "_exit")

opt("MouseCoordMode" , 2)

Opt("PixelCoordMode", 2)

WinActivate("World Golf Tour - Mozilla Firefox")

$var = PixelGetColor( 677, 685)

MouseClickDrag("left",677, 685, 500, 300)

Do

Until $var = 0x92E74D

MouseClick("left", 677, 685)

Func _exit()

;exits the script

Exit

EndFunc

I will try that pixel checksum when I get home, I hope I can get it to work, this seems so simple to do, but it is giving me so many problems.

Thank you for your help, I appreciate it greatly!

Share this post


Link to post
Share on other sites

No problem, I sometimes like helping, and this is one of those times because for some reason I am intrigued by this >_<

A question here, what is the MouseDrag for? After something is 'MouseDragged', the 'select highlight' color could be an issue here.

And in the Do loop, the PixelGetColor check needs to be done and re-done Until.. Right now in your code it says 'do nothing until..' but $var won't change because it's not checked again.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

The mouse drag works perfectly, goes to the bottoom drags up 300 pixels and releases!

The only problem is that pixel detection logic. Do I need to change it to this?

Do

$var = PixelGetColor( 677, 685)

Until $var = 0x92E74D

I am at work so I cannot test till I get off work.

Share this post


Link to post
Share on other sites

The Do.. Until logic seems OK to me, but perhaps checking if/when $var doesn't equal (<>) what it did originally would be better, if I'm wrong about the Do.. Until. I realize you can't actually check these things now, but don't forget about the PixelCheckSum suggestion..

And I'm still confused about the Drag, more exactly why it's there/needed, but if it performs as you intend, then all's good with that.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

To give you a better undestanding why the drag is there, If you ever played any golf games, it is a 2 click process(some golf games use a 3 click this game doesn't) to hit the ball, look at my pics a few posts back:

1st click: the meter goes from right to left to give you your power to hit the ball.

2nd click: the meter goes back from left to right and depending on wheer you click determines your accuracy of the hit.

so if you see in my picture, that green line going from left to right is accuracy, and clicking right on the white line is a perfect shot.

I think that is what it is doing, do Until $var = 0x92E74D<-- this is the green color.

what do you think?

Edited by inmysights

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