Keypress when pixel color turns red

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
daffy82
Posts: 14
Joined: 03 Aug 2016, 00:42

Keypress when pixel color turns red

03 Aug 2016, 00:45

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?
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: Keypress when pixel color turns red

03 Aug 2016, 01:31

Code: Select all

SetTimer, Monitor, 5000 ; 5 seconds
return

monitor()
{
    PixelGetColor, ColorVar, 100, 100
    ToolTip, %ColorVar%
    if (colorVar = "0x" . "FF0000")
        send 5
}
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
daffy82
Posts: 14
Joined: 03 Aug 2016, 00:42

Re: Keypress when pixel color turns red

03 Aug 2016, 03:45

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.
User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: Keypress when pixel color turns red

03 Aug 2016, 04:11

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.
daffy82
Posts: 14
Joined: 03 Aug 2016, 00:42

Re: Keypress when pixel color turns red

03 Aug 2016, 07:45

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.
Ok thanks for explaining.

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
User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: Keypress when pixel color turns red

03 Aug 2016, 07:57

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.
p3trus
Posts: 137
Joined: 02 Aug 2016, 03:20

Re: Keypress when pixel color turns red

03 Aug 2016, 08:05

...guess you need it for something like monitoring a health bar and use a health potion by pressing "5"?

Then consider using a Loop:

Code: Select all

Loop, {
	; your check here
}
If your script has also to perform other tasks, better use self-reactivating ONE-TIME-Timers:

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
}
daffy82
Posts: 14
Joined: 03 Aug 2016, 00:42

Re: Keypress when pixel color turns red

03 Aug 2016, 23:59

p3trus wrote:...guess you need it for something like monitoring a health bar and use a health potion by pressing "5"?
Yes - exactly. Thanks.
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.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lpanatt, macromint, peter_ahk and 284 guests