| View previous topic :: View next topic |
| Author |
Message |
MasterFocus
Joined: 08 Apr 2009 Posts: 3035 Location: Rio de Janeiro - RJ - Brasil
|
Posted: Fri May 01, 2009 1:35 am Post subject: WaitPixelColor() |
|
|
Useful function I develop once to fulfill my needs.
+ 19/july
- Fixed a logical mistake
USAGE + FUNCTION (download)
| Code: | ;========================================================================
;
; Function: WaitPixelColor
; Description: Waits until pixel is a certain color (w/ optional timeout)
; Online Ref.: http://www.autohotkey.com/forum/topic43807.html
;
; Last Update: 19/July/2009 04:30
;
; Created by: MasterFocus
; http://www.autohotkey.net/~MasterFocus/AHK/
;
;========================================================================
;
; p_DesiredColor, p_PosX, p_PosY [, p_TimeOut, p_GetMode, p_ReturnColor]
;
; + Required parameters:
; - p_DesiredColor The color you are waiting for
; - p_PosX, p_PosY Pixel coordinates
;
; + Optional parameters:
; - p_TimeOut Timeout in milliseconds (default is 0, no timeout)
; - p_GetMode PixelGetColor mode(s) (default is blank)
; - p_ReturnColor Boolean, see returned values below (deafult is 0)
;
; + Returned values when ReturnColor is 0 (false):
; - 0 The desired color was found
; - 1 There was a problem during PixelGetColor
; - 2 The function timed out
;
; + Returned values when ReturnColor is 1 (true):
; - Blank There was a problem during PixelGetColor
; - Non-blank Will be the latest found color, even if not the desired one
;
;========================================================================
WaitPixelColor(p_DesiredColor,p_PosX,p_PosY,p_TimeOut=0,p_GetMode="",p_ReturnColor=0)
{
l_Start := A_TickCount
Loop
{
PixelGetColor, l_RetrievedColor, %p_PosX%, %p_PosY%, %p_GetMode%
If ErrorLevel
{
If !p_ReturnColor
Return 1
Break
}
If ( l_RetrievedColor = p_DesiredColor )
{
If !p_ReturnColor
Return 0
Break
}
If ( p_TimeOut ) && ( A_TickCount - l_Start >= p_TimeOut )
{
If !p_ReturnColor
Return 2
Break
}
}
Return l_RetrievedColor
} |
EXAMPLE (download)
| Code: | #Include WaitPixelColor.ahk
CoordMode, Pixel, Screen
MsgBox % "This example will wait for pixel at 0,0 to be black."
MsgBox % WaitPixelColor(0,0,0) |
_________________ "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
Last edited by MasterFocus on Tue Jun 08, 2010 6:38 pm; edited 7 times in total |
|
| Back to top |
|
 |
JulieXP
Joined: 24 Oct 2004 Posts: 93 Location: NYC
|
Posted: Wed May 06, 2009 5:09 am Post subject: |
|
|
aww your the best!
thanks for sharing with the rest of the community! _________________ -Julie |
|
| Back to top |
|
 |
JulieXP
Joined: 24 Oct 2004 Posts: 93 Location: NYC
|
Posted: Wed May 06, 2009 11:47 am Post subject: |
|
|
What im i doing wrong? i cant figure it out
| Quote: |
WaitPixelColor(0xBC6A23,458,29,GetMode="",ReturnMode=0,SleepTime=1,TimeoutMult=0)
{
Loop
{
Sleep, %SleepTime%
PixelGetColor, RetrievedColor, %PosX%, %PosY%, %GetMode%
if ErrorLevel
{
if !ReturnMode
MsgBox, Error
break
}
if RetrievedColor = %DesiredColor%
{
if !ReturnMode
MsgBox, got the color
break
}
if A_Index = %TimeoutMult%
{
if !ReturnMode
MsgBox, timed out
break
}
}
return RetrievedColor
} |
_________________ -Julie |
|
| Back to top |
|
 |
JulieXP
Joined: 24 Oct 2004 Posts: 93 Location: NYC
|
Posted: Wed May 06, 2009 11:40 pm Post subject: |
|
|
never mind i got it, thanks tho _________________ -Julie |
|
| Back to top |
|
 |
R3TR0
Joined: 26 Aug 2009 Posts: 38 Location: Canada
|
Posted: Wed Sep 02, 2009 8:52 pm Post subject: |
|
|
Hey very nice function, adding to my library  |
|
| Back to top |
|
 |
spazpunt
Joined: 12 Jul 2009 Posts: 71
|
Posted: Mon Sep 07, 2009 12:48 am Post subject: |
|
|
| can this be made to work for a particular window such as desktop user picture??? |
|
| Back to top |
|
 |
MasterFocus
Joined: 08 Apr 2009 Posts: 3035 Location: Rio de Janeiro - RJ - Brasil
|
Posted: Tue Sep 08, 2009 1:27 am Post subject: |
|
|
You may add WinActivate before the PixelGetColor command for a quick work-around. _________________ "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 |
|
 |
Ripperjack
Joined: 24 Aug 2009 Posts: 14
|
Posted: Sat Oct 03, 2009 9:54 pm Post subject: |
|
|
I want to do something simple using this script.
I want to look at a coordinate of 200,700 for the color 0. And tell me what it found, so:
| Code: | #Include WaitPixelColor.ahk
^a::
WaitPixelColor(0,225,700,10000)
If errorlevel = 0
(
Msgbox Found it.
Return
)
Else if errorlevel = 1
(
Msgbox Error
return
)
Else Errorlevel = 2
(
Msgbox Timed out.
Return
) |
Or am I just completely misunderstanding this function? |
|
| Back to top |
|
 |
Rabiator
Joined: 17 Apr 2005 Posts: 289 Location: Sauerland
|
Posted: Sun Oct 04, 2009 8:26 am Post subject: |
|
|
At a first glance:
| Code: | If errorlevel = 0
{
Msgbox Found it.
Return
}
Else if errorlevel = 1
{
Msgbox Error
return
}
Else if Errorlevel = 2
{
Msgbox Timed out.
Return
} |
__________________________________________
Created with BBCodeWriter 7.0 - the one and only  |
|
| Back to top |
|
 |
MasterFocus
Joined: 08 Apr 2009 Posts: 3035 Location: Rio de Janeiro - RJ - Brasil
|
Posted: Sun Oct 04, 2009 4:45 pm Post subject: |
|
|
| Ripperjack wrote: | | Or am I just completely misunderstanding this function? |
Yes, because that's not the way you call a function.
You should use the returned value instead of ErrorLevel, as I specified:
| MasterFocus wrote: | ; + Return values when ReturnMode is 0:
; - 0 The desired color was found
; - 1 There was a problem during PixelGetColor
; - 2 The function timed out |
Read more about about Functions and Blocks.
Here's what your code should look like:
| Code: | #Include WaitPixelColor.ahk
Return
^a::
var := WaitPixelColor(0,225,700,10000)
If ( var = 0 )
Msgbox Found it.
Else If ( var = 1 )
Msgbox Error!
Else If ( var = 2 )
MsgBox Timed out.
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 |
|
 |
Scottieboy
Joined: 08 Jan 2010 Posts: 9
|
Posted: Fri Jan 08, 2010 12:07 pm Post subject: Pixels change colour |
|
|
Masterfocus, Thanks very much for this great little script. It has helped me automate some procedures to make life easier in running monotonous routines.
I do have an issue though. The script works fine when I run locally. However, for some reason when I connect to a machine to run remotely through citrix/Remote desktop, the pixel color is different. I believe this to be because the desktop runs in 32 bit colours locally, whereas remote desktop will only function in 16bit.
Is there a way of getting this script to work by including a wider pallet of colours? I mean, if the colour is within a certain amount of shades it will work?
I appreciate this is my first post, but I do look through this forum and find my answers instead of posting without research like some!
Thanks in advance,
Scott |
|
| Back to top |
|
 |
MasterFocus
Joined: 08 Apr 2009 Posts: 3035 Location: Rio de Janeiro - RJ - Brasil
|
Posted: Fri Jan 15, 2010 6:47 am Post subject: |
|
|
Sorry, but I'm far from being the correct person to talk about these Remote Desktop and GetPixelColor coding stuff.
Try creating a topic or visiting the IRC channel. _________________ "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 |
|
 |
Scottieboy
Joined: 08 Jan 2010 Posts: 9
|
Posted: Mon Feb 01, 2010 9:37 am Post subject: |
|
|
Thanks for the reply. I resolved this issue in the end by using Dameware instead of remote desktop.
Scott |
|
| Back to top |
|
 |
Jinan
Joined: 08 Mar 2010 Posts: 11
|
Posted: Thu Apr 22, 2010 3:46 pm Post subject: |
|
|
| it does what i am looking for! million ths~! |
|
| Back to top |
|
 |
borgman
Joined: 17 Jun 2010 Posts: 70
|
Posted: Sat Jun 19, 2010 6:38 pm Post subject: |
|
|
Might be a silly question but how do add something like this to my library, i.e. where do I save your download code in a file such that in future scripts I can simply begin with #Include WaitPixelColor.ahk ?
Many thanks |
|
| Back to top |
|
 |
|