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!
New Scripter - Colour Detection
-
- Posts: 14
- Joined: 02 Apr 2016, 05:00
Re: New Scripter - Colour Detection
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.
Here's what I got so far.
Spoiler
Re: New Scripter - Colour Detection
CoordMode doesn't work that way. You need separate commands on separate lines. One for Pixel and one for Mouse.
-
- Posts: 14
- Joined: 02 Apr 2016, 05:00
Re: New Scripter - Colour Detection
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.
Re: New Scripter - Colour Detection
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
-
- Posts: 14
- Joined: 02 Apr 2016, 05:00
Re: New Scripter - Colour Detection
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.
Re: New Scripter - Colour Detection
What I'm saying is that if you correct the CoordMode statements, it probably will work.
Re: New Scripter - Colour Detection
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
-
- Posts: 14
- Joined: 02 Apr 2016, 05:00
Re: New Scripter - Colour Detection
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.
Re: New Scripter - Colour Detection
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.
-
- Posts: 14
- Joined: 02 Apr 2016, 05:00
Re: New Scripter - Colour Detection
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 ?
Re: New Scripter - Colour Detection
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.
-
- Posts: 14
- Joined: 02 Apr 2016, 05:00
Re: New Scripter - Colour Detection
Got it. Thanks a lot.
Who is online
Users browsing this forum: erann and 69 guests