New Scripter - Colour Detection

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Rhaom
Posts: 1
Joined: 04 Apr 2016, 09:44

New Scripter - Colour Detection

04 Apr 2016, 09:48

Hello,

I am new to AHK and looking to get started with, what seemingly would be a very simple colour detected macro.

Basically, I am looking for a pointer in the right direction on how to create a 3 step macro.

Press X
Detect colour Y and move mouse to it
Right click
Repeat

Any help / pointer in the best place to start would be fantastic! :)
WhatIsWindows
Posts: 14
Joined: 02 Apr 2016, 05:00

Re: New Scripter - Colour Detection

05 Apr 2016, 07:30

I'm trying to do kind of the same thing, but I have it scanning a rectangle of coordinates and then move the mouse on and do a left click if it finds the color of the pixel specified. I don't know how I can make it click on the colored pixel it's looking for though, instead it clicks on a random location between the specified coordinates.

Here's what I got so far.
Spoiler
User avatar
boiler
Posts: 16989
Joined: 21 Dec 2014, 02:44

Re: New Scripter - Colour Detection

05 Apr 2016, 08:30

CoordMode doesn't work that way. You need separate commands on separate lines. One for Pixel and one for Mouse.
WhatIsWindows
Posts: 14
Joined: 02 Apr 2016, 05:00

Re: New Scripter - Colour Detection

05 Apr 2016, 09:39

Mm, I don't know how to do that yet so I'm leaving it at that. The tutorial page doesn't cover that part or I just can't read it from there. It's nothing important, just tried it for practice.
User avatar
boiler
Posts: 16989
Joined: 21 Dec 2014, 02:44

Re: New Scripter - Colour Detection

05 Apr 2016, 10:12

Why do you say it's not important? Not only is it important, it's absolutely critical to your script having a chance of working. If your coordinate modes don't match between your pixel search and your mouse click, it has absolutely no chance of working. It just needs to be two separate statements like this:

Code: Select all

CoordMode, Pixel, Window
CoordMode, Mouse, Window
WhatIsWindows
Posts: 14
Joined: 02 Apr 2016, 05:00

Re: New Scripter - Colour Detection

05 Apr 2016, 10:24

Oh no, I meant not important as my script is nothing of importance as it's just for practice. It's just that I don't know how to make the mouse move to and click on the pixel that it detects the color in. Right now it only clicks in a random location between the preset rectangle of coordinates.
User avatar
boiler
Posts: 16989
Joined: 21 Dec 2014, 02:44

Re: New Scripter - Colour Detection

05 Apr 2016, 10:26

What I'm saying is that if you correct the CoordMode statements, it probably will work.
User avatar
boiler
Posts: 16989
Joined: 21 Dec 2014, 02:44

Re: New Scripter - Colour Detection

05 Apr 2016, 10:30

The reason it was clicking at a random place is you didn't include the else commands in braces, so the click happened no matter what (and because if it did find the color, your coordinate modes weren't set right). You also don't need the % signs in MouseMove.

Code: Select all

#SingleInstance force
 
Esc::
 
CoordMode, Pixel, Window
CoordMode, Mouse, Window
PixelSearch, PixelX, PixelY, 389,389,573,573, B8ADAC, 30, Fast RGB
 
 
	If ErrorLevel
		MsgBox, Color not found.
 
	Else
	{
		MouseMove, PixelX, PixelY
		Click
	}
	Return
WhatIsWindows
Posts: 14
Joined: 02 Apr 2016, 05:00

Re: New Scripter - Colour Detection

05 Apr 2016, 11:14

Yep, I did that. Now it clicks on certain coordinates every time it finds the color in the specified area but not on the colored pixel it finds. I tuned down the variation to 1 aswell to make sure it doesn't count surrounding colors. Basically the pixel it's looking for is greyish-white and surrounding is different shades of brown.
User avatar
boiler
Posts: 16989
Joined: 21 Dec 2014, 02:44

Re: New Scripter - Colour Detection

05 Apr 2016, 13:04

Your color ID needs to be 0xB8ADAC, not B8ADAC. Without the 0x in front, you are just specifying a variable named B8ADAC which has a null value.
WhatIsWindows
Posts: 14
Joined: 02 Apr 2016, 05:00

Re: New Scripter - Colour Detection

05 Apr 2016, 14:27

Doesn't work like that either, we can leave it there, appreciate the input though. One thing I'm curious about is why it wants 2 X coordinates and 2 Y coordinates when the X1 X2 and Y1 Y2 are the same coordinate ?
User avatar
boiler
Posts: 16989
Joined: 21 Dec 2014, 02:44

Re: New Scripter - Colour Detection

05 Apr 2016, 15:05

They're not the same coordinate. You need two different X,Y coordinates to be able to define any possible rectangle. And you also chose two different coordinates: The first is X1=389, Y1=389, and the other coordinate is at X2=573, Y2=573. If you meant for them to be the same coordinate (to define a rectangle of 1 pixel in size), it would have needed to be (for example) X1=389, Y2=573 and X2=389, Y2=573.
WhatIsWindows
Posts: 14
Joined: 02 Apr 2016, 05:00

Re: New Scripter - Colour Detection

06 Apr 2016, 05:23

Got it. Thanks a lot.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: erann and 69 guests