AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

IF Color

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
ZyanWu
Guest





PostPosted: Thu Mar 04, 2010 1:36 am    Post subject: IF Color Reply with quote

Ok, here's the deal:

Code:
1::
PixelGetColor, color, 0,  0
IfEqual, color, 0x020101
{
send 3
} else {
send 2
}
return


This script has 2 stupid things it has to do:
1: if the current color at 0.0 is BLACK (well 0x020101 to be more exact)
then press 3!
2: if it is not BLACK
press 2!

The problem is that the line "IfEqual, color, 0x020101" doesn't return true when the color IS BLACK.

What the hell am I doing wrong? Shocked
Back to top
Guest






PostPosted: Thu Mar 04, 2010 1:41 am    Post subject: Re: IF Color Reply with quote

ZyanWu wrote:
What the hell am I doing wrong? Shocked

...I'm not sure, ask msgbox...

Code:
1::
PixelGetColor, color, 0,  0
msgbox, color(%color%)
return

...whenever an if doesn't do what you expect, use msgbox, to see what the if sees...
Back to top
None



Joined: 28 Nov 2009
Posts: 3086

PostPosted: Thu Mar 04, 2010 1:45 am    Post subject: Reply with quote

Are you looking for the Pixel at 0,0 on screen or on current window?
If You want it on screen you need to change CoordMode and Black is 0x000000
Back to top
View user's profile Send private message
Guest






PostPosted: Thu Mar 04, 2010 1:51 am    Post subject: Reply with quote

None wrote:
Black is 0x000000

...yes, but I'm pretty sure he really wants 0x020101 (or maybe 0x010102 depending on if his number is BGR or RGB)...

Code:
1::
CoordMode, Pixel
PixelGetColor, color, 0, 0
msgbox, color(%color%)
return

...I really hate the default of everything being Active Window instead of Screen...I NEVER want anything based on the active window...
Back to top
ZyanWu
Guest





PostPosted: Thu Mar 04, 2010 1:56 am    Post subject: IF Color Reply with quote

No, no, please don't worry about the coords or the color.

My script runs like this:
I press 1, PixelGetColor does his job and returns a color (for ex. 0x3345AF), then the IF does the job right and executes Send 2.

The problem is when I press 1, PixelGetColor returns 0x020101 and the IF Clause is still false. Neutral But it can't be, I did a msgbox with %color% and it returned 0x020101.
This is where I'm lost: why doesn't "IfEqual, color, 0x020101" return TRUE when the color is 0x020101 and execute Send 3?
Back to top
Guest






PostPosted: Thu Mar 04, 2010 2:10 am    Post subject: Re: IF Color Reply with quote

I don't use or debug IfEqual, but if this fails, I'm lost...

Code:
1::
CoordMode, Pixel
PixelGetColor, color, 0, 0
if (color="0x020101") {
   msgbox, 64, , TRUE: Send, 3`n`ncolor(%color%)
} else {
   msgbox, 64, , FALSE: Send, 2`n`ncolor(%color%)
}
return

...remove "CoordMode, Pixel" if you really don't want 0,0 of the screen...
Back to top
MasterFocus



Joined: 08 Apr 2009
Posts: 3035
Location: Rio de Janeiro - RJ - Brasil

PostPosted: Thu Mar 04, 2010 2:24 am    Post subject: Reply with quote

After you double check the correct color, you may want to use this:
Code:
1::
  CoordMode, Pixel, Screen
  PixelGetColor, color, 0,  0
  Send, % 2 + ( color = 0x020101 ) ; be sure about the color
Return

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"

Antonio França
My stuff: Google Profile
Back to top
View user's profile Send private message Visit poster's website
ZyanWu
Guest





PostPosted: Thu Mar 04, 2010 2:28 am    Post subject: IF Color Reply with quote



I may not be crazy after all.

PS. It worked ONCE. Just once. Neutral
Back to top
Guest






PostPosted: Thu Mar 04, 2010 7:19 am    Post subject: Re: IF Color Reply with quote

I'm sorry, what is that screenshot supposed to show? It failing? What sets the Pixels color? Where is the pixel? (0,0 Screen or 0,0 of a specific window) Also, in that code you tested pixel 1,1 of the screen for 0x000000 (nothing like previous tests) & as far as I can tell the pixel in question is not in the screenshot so I can't verify the scripts result. What version of AutoHotkey do you have? Try the Alt & Slow modes of PixelGetColor?
Back to top
Guest






PostPosted: Thu Mar 04, 2010 7:28 am    Post subject: Re: IF Color Reply with quote

Actually, wait a minute, lets just see if you are crazy...(or if your AutoHotkey is)...screw PixelGetColor, try this...

Code:
1::
color:="0x020101"
Gosub, AreYouCrazy
return

2::
color:="0x191919"
Gosub, AreYouCrazy
return

AreYouCrazy:
if (color="0x020101") {
   msgbox, 64, , TRUE: Send, 3`n`ncolor(%color%)
} else {
   msgbox, 64, , FALSE: Send, 2`n`ncolor(%color%)
}
return

...that should get you 100% consistent results, if that works, we're back to needing to care about the pixel again...
Back to top
MasterFocus



Joined: 08 Apr 2009
Posts: 3035
Location: Rio de Janeiro - RJ - Brasil

PostPosted: Thu Mar 04, 2010 2:34 pm    Post subject: Reply with quote

Remember: CoordMode !
_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"

Antonio França
My stuff: Google Profile
Back to top
View user's profile Send private message Visit poster's website
DevX



Joined: 07 Jan 2009
Posts: 43

PostPosted: Thu Mar 04, 2010 2:43 pm    Post subject: Reply with quote

ZyanWu's code works fine for me. Mine returns true, while yours returns false hahaha. My color changed because of desktop

Code:
1::
CoordMode, Pixel
PixelGetColor, color, 1, 1
MsgBox % color

if (color = "0x131012")
{
  MsgBox % "hello color - " . color
}
else
{
  MsgBox % "goodbye color - " . color
}

return
Back to top
View user's profile Send private message
ZyanWu
Guest





PostPosted: Thu Mar 04, 2010 10:34 pm    Post subject: IF Color Reply with quote

Hey, thanks for the help guys, it worked fine today. I don't know what the problem was, probably someone cursed me or somethin'. Rolling Eyes
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group