PixelGetColor, NoteColor, 960, 1050 ; NoteColor is the color of the note
Loop
{
PixelGetColor, NoteColorTap, 960, 1050 ; NoteColorTap is the color of the note when you're supposed to tap it
if %NoteColorTap% != %NoteColor% ; If colors don't match
SendInput, {space} ; Tap the note using the space bar
}
It's supposed to continuously check the Pixel Color of the note, and when it changes you tap it once. But my code above simply taps continuously with no regard to the changing colors. Any help is appreciated.
f1:: ;trigger to start the program, change to what works for you
loop
{
PixelGetColor, NoteColor, 960, 1050 ; NoteColor is the color of the note
Loop
{
PixelGetColor, NoteColorTap, 960, 1050 ; NoteColorTap is the color of the note when you're supposed to tap it
if (%NoteColorTap% != %NoteColor%) ; If colors don't match
{
SendInput, {space} ; Tap the note using the space bar
sleep, 50 ;fiddle with this, you need to give the program a chance to refresh the screen before getting the colors again
break ;you need to get out of this loop to get the new note from the first loop
}
}
}
esc::escape ;good to have an exit in case of a bug
Hi grant, thanks for the help. I managed to make it work with one note at a time.
However, my problem now is that there are multiple note placements on the screen. With the current code, it only works on the middle note.
How would I go about making this work for 3 notes on the screen? My attempt so far uses SetTimer to run 3 Loops. Unfortunately, when I activate more than one timer, the script doesn't work anymore.
Multiple timers start tripping over each other and you may need to use other methods.
Spoiler
To better explain, if you have a trigger that is not yet completed and another is started, the new one must finish and then the old one (that did not finish) will pick-up from where it was interrupted. The timers can also be interrupted more than once, potentially causing a timer to never complete because it keeps getting interrupted.
1 runs for 5 seconds ever 15 seconds
2 runs for 10 seconds every 20 seconds
3 runs for 15 seconds every 40 seconds.
Keep track of the starting times with a watch and you will see that 1 is correct for the first 3 loops and then is knocked out of time, while timer3 does not even start on schedule the first time.
f1::
SetTimer, timer1, 15000
SetTimer, timer2, 20000
SetTimer, timer3, 40000
return
timer1:
timer1 := 5
while timer1 > 0
{
ToolTip, This is timer 1 and will run for 5 seconds (every 15 seconds) - %timer1%, 200, 150
sleep, 1000
timer1 := timer1 - 1
}
ToolTip, , 200, 150
return
timer2:
timer2 := 10
while timer2 > 0
{
ToolTip, This is timer 2 and will run for 10 seconds (every 20 seconds) - %timer2%, 400, 150
sleep, 1000
timer2 := timer2 - 1
}
ToolTip, , 400, 150
return
timer3:
timer3 := 15
while timer3 > 0
{
ToolTip, This is timer 3 and will run for 15 seconds (every 40 seconds) - %timer3%, 600, 150
sleep, 1000
timer3 := timer3 - 1
}
ToolTip, , 600, 150
return
esc::exitapp
I would start with multiple toolboxes to display on screen the notes (colors). Do this for all the various note locations you use above and all at the same time so you can see how they interact. Then you can start to think about how you can use the colors and how they change to trigger the various sends that you have.
If you see that the active note is the only fixed pixel, then you can use that as a trigger.
If they are all stationary, then you will have to monitor all of them to determine which one changes.
If the new note is displayed instantaneously, you will have 2 changes, so you will then need to keep track of the previous note as well so that you know which one of the 2 to monitor.
If they are all, always changing, you have a different challenge and perhaps your note is changing less than the others and you can use that.
I do not think that this is not a *difficult* problem, but it is a nice challenge. There are potentially many variables that can influence how you need to approach this.
grant wrote:If they are all stationary, then you will have to monitor all of them to determine which one changes.
This seems most relevant to my game. So far I've set 9 ToolTips to monitor each note position. As you can see from the image, the notes that I have to tap are the red circles that start at the top center and move towards the note positions. PixelGetColor keeps track of a pixel on the border of the note position. When the red circle overlaps, then PixelGetColor should be different than usual. If that's the case, then I send an Input to tap that note.
But my problem now becomes how to monitor 9 individual note positions. You've taught me that SetTimer can't mirror threading, so I wonder if there's an alterative in AHK.
That is not what I meant for you to use the tooltip for. Use the tooltip to visually see if and when the color changes, games often have a bit of color change to keep your attention or distract and these are sometimes minor enough that you can not see them but they will effect your program.
Stationary???? - What drivel was I typing??? - I meant fixed, i.e. the color does not change at all.