 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
whocares
Joined: 15 Jul 2007 Posts: 6
|
Posted: Mon Jul 16, 2007 4:31 am Post subject: Separate commands from the loop |
|
|
wantedColor = 0xFFFFFF
crossX = 40
crossY = 78
Loop
{
PixelGetColor, notepadColor, %crossX%, %crossY%
if %ErrorLevel% = 0
Sendplay hello
sleep 200
}
This is a script I found that will send "hello" repeatedly whenever a pixel at the specified coordinates are the correct color. I'd like the script to work so that once the correct color is detected the script sends "hello" only once, instead of looping it. |
|
| Back to top |
|
 |
mwharri
Joined: 15 Mar 2007 Posts: 70
|
Posted: Mon Jul 16, 2007 7:24 am Post subject: |
|
|
| Code: |
wantedColor = 0xFFFFFF
crossX = 40
crossY = 78
Loop
{
PixelGetColor, notepadColor, %crossX%, %crossY%
if %ErrorLevel% = 0
Sendplay hello
sleep 200
}
|
I think this should work...untested
| Code: |
msgSentOnce = 0
wantedColor = 0xFFFFFF
crossX = 40
crossY = 78
SetTimer, isColorThere, 1000
isColorThere:
if msgSentOnce
Return
PixelGetColor, notepadColor, %crossX%, %crossY%
if ! ErrorLevel
{
Sendplay hello
msgSentOnce = 1
}
Return
|
You could also take out the msgSentOnce variable references and change to | Code: | | SetTimer, isColorThere, off |
It just depends on what you're trying to do if the color is found. |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Mon Jul 16, 2007 6:16 pm Post subject: |
|
|
a simple adjustment to your code, (though the other reply looks more useful)
| Code: |
wantedColor = 0xFFFFFF
crossX = 40
crossY = 78
Loop
{
PixelGetColor, notepadColor, %crossX%, %crossY%
if %ErrorLevel% = 0
Break
sleep 200
}
Sendplay hello
|
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|