Hi.
Im looking for a script that will monitor one pixel and if that pixel chages color it should press "5"
Is it possible to have it run infinitely - until I stop the script?
Keypress when pixel color turns red
- Blackholyman
- Posts: 1293
- Joined: 29 Sep 2013, 22:57
- Location: Denmark
- Contact:
Re: Keypress when pixel color turns red
Code: Select all
SetTimer, Monitor, 5000 ; 5 seconds
return
monitor()
{
PixelGetColor, ColorVar, 100, 100
ToolTip, %ColorVar%
if (colorVar = "0x" . "FF0000")
send 5
}
Courses on AutoHotkey
My Autohotkey Blog
![Yay! Dance! Yay! :dance:](./images/smilies/dance.gif)
Re: Keypress when pixel color turns red
Blackholyman - Thanks. I will test this later.
Can I ask:
This line: (colorVar = "0x" . "FF0000")
"0x" is how 'sensitive' AHK is about the colors? Shades of color? and "FF0000" is the color itself, right?
Also this line: SetTimer, Monitor, 5000 ; 5 seconds
Why 5 secs? Can the script run continuously until I stop it.
(im trying to learn
Again thx for taking your time.
Can I ask:
This line: (colorVar = "0x" . "FF0000")
"0x" is how 'sensitive' AHK is about the colors? Shades of color? and "FF0000" is the color itself, right?
Also this line: SetTimer, Monitor, 5000 ; 5 seconds
Why 5 secs? Can the script run continuously until I stop it.
(im trying to learn
![Smile :)](./images/smilies/icon_e_smile.gif)
Again thx for taking your time.
Re: Keypress when pixel color turns red
No, "0x" indicates that it is a number in hexadecimal format. Yes, "FF0000" is the color in BGR format, this one being pure blue.
It doesn't just run for 5 seconds. It runs indefinitely, checking the pixel every 5 seconds, which you can change.
It doesn't just run for 5 seconds. It runs indefinitely, checking the pixel every 5 seconds, which you can change.
Re: Keypress when pixel color turns red
Ok thanks for explaining.boiler wrote:No, "0x" indicates that it is a number in hexadecimal format. Yes, "FF0000" is the color in BGR format, this one being pure blue.
It doesn't just run for 5 seconds. It runs indefinitely, checking the pixel every 5 seconds, which you can change.
I guess I would set it to '5' instead of '5000' because I need it to be triggered instantly. Cant wait to get home and test this out. I will report back
Re: Keypress when pixel color turns red
Since it won't actually be able to perform the Monitor function in 5 ms, you are basically asking it to run the check as often as possible with no delay. That's OK, but you might want to keep an eye on CPU usage and see if it's too high for you. It might also send "5" many times before the pixel changes, which may or not be what you want.
Re: Keypress when pixel color turns red
...guess you need it for something like monitoring a health bar and use a health potion by pressing "5"?
Then consider using a Loop:
If your script has also to perform other tasks, better use self-reactivating ONE-TIME-Timers:
Then consider using a Loop:
Code: Select all
Loop, {
; your check here
}
Code: Select all
SetTimer, Monitor, -1 ; 1ms, but only one time with that "-"
return
Monitor()
{
; your check here
SetTimer, Monitor, -1 ; schedule the same function again for one run
}
Re: Keypress when pixel color turns red
Yes - exactly. Thanks.p3trus wrote:...guess you need it for something like monitoring a health bar and use a health potion by pressing "5"?
I just realized that when I get hit ingame the numbers turns red in a fraction of a secound. I thought that the numbers were only red when health was at 20 or under... So this wont work. But this was still very good info! Thank you all.
Instead of pixelsearch I will look at image recognition. I will make a new thread on this.