PixelGetcolor, and if few condition are true then click. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Dumitas
Posts: 167
Joined: 14 Dec 2017, 21:32

PixelGetcolor, and if few condition are true then click.

15 Dec 2017, 23:46

Hi! Im new on AHK and not good at coding, what I learn I did recently and from this forum.

Im working on a simple script that detect a color and click on different coordinates based on the color.

This is what Im using right now:

Code: Select all

x::
    PixelGetColor, Pix, 123, 123
    IfEqual, Pix, COLOR1 , click, 234, 234, 2
    IfNOTEqual, Pix,  COLOR1, click, 321, 321,
return
(just an example, not real colors or coordinates)

Pretty simple, if the color its the one I'm looking for then double click on coordinates if not, click on different coordinates.

But what I really want its a persistent script that detect one color if that color match, then go to the script on the top or similar, Im gonna try to write a scrit using simple english mixed with code just to show what I want:

Code: Select all

 ;step 1
PixelGetColor, Pix1, X1,Y1
if Pix1 = Color1 ;(ONLY IF, GO FOR THE NEXT PixelGetColor)
sleep 3000 ; Sleep 3 sec and go to the next pixelgetcolor (stop retriving Pix1)
 ;step 2
PixelGetColor, Pix2, X2,Y2
if Pix2 = Color2 
Click, 123, 123,
else if Pix2 != Color2
; don't know if "else if" or not equal are valid, I want to be able to create as many condition as I want based on the color.
Click, 321, 321,
 ;step 3
sleep 10000
(star over)
This not near to a real code, what I want is to detect a pixel (persistent) and when this pixel change to the color I want then (wait) detect another pixel and if this pixel its the color I want click on coord if not click on another coord, wait again (10sec) and start over from the first pixelgetcolor and just keep doing that.
I only want to start retriving Pix2 if Pix1 its correct, otherwise its keep searching for the color. I said persistent but If I had an On / Off key the better.

I'm really bad explaining things, but I hope someone can undestand and help me to do this code, once I have the code I will be able to modify at will and maybe twik it a little bit.

Thank you in advance

PS: I know that PixelGetColor can keep retriving color instead of stop, but what I want requiere multiple conditions and if those multiple conditions are true then take action.
Image
John316
Posts: 13
Joined: 15 Dec 2017, 08:53

Re: PixelGetcolor, and if few condition are true then click.  Topic is solved

16 Dec 2017, 07:34

Hello Dumitas..

You can try something like this..

Code: Select all

Color1 = Red ;<-- put the color1 value here to check it later
Color2 = Blue ;<-- put the color2 value here to check it later
;step 1
Loop 	; this will loop and check for the colors. If no match it waits 1 second then starts again
{
	PixelGetColor, Pix1, X1,Y1
	if Pix1 = Color1 ;(ONLY IF, GO FOR THE NEXT PixelGetColor)
	{
		sleep 3000 ; Sleep 3 sec and go to the next pixelgetcolor (stop retriving Pix1)
		 ;step 2
		PixelGetColor, Pix2, X2,Y2
		if Pix2 = Color2
		{
			MouseClick, Left, %X2%, %X2% ; just guessing on the x y coords
		}
		else if Pix2 != Color2
		{
			MouseClick, Left, %X1%, %X1% ; just guessing on the x y coords
		}
	}
	else
	{
		Sleep, 1000 ; If your 1st color isn't found wait 1 second
	}
}

Esc::ExitApp ; press the ESC key to exit
Look into...

https://autohotkey.com/docs/commands/Loop.htm
https://autohotkey.com/docs/Hotkeys.htm

The hotkeys will help you with an ON/OFF type of switch.
User avatar
Dumitas
Posts: 167
Joined: 14 Dec 2017, 21:32

Re: PixelGetcolor, and if few condition are true then click.

16 Dec 2017, 21:11

Gotcha, thank you very much, Now I undestand how to add more conditions if the first one its true, that was my biggest problem because I tried myself but when Color1 was found and not the second it keep looping (clicking) on "Pix2 != Color2" because this condition its always true even when Color1 don't.


Thank you!
Image

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Raymondbit and 387 guests