(11)Getting pixel color and coords :
11.1 Introduction:
In this sample im going to teach how to get a pixelcolor and the position of the mouse by pressing a HotKey, in this case the Space bar.
11.2 The code:
Open NOTEPAD and copy the next code into it, save it as a .ahk file and double click to see the result.
Quote:
; getting coords and color
Gui, Show , w250 h50, Info
; only a text
Gui, Add, Text, x10 y12 Left, Press <SPACE> to pick up color and position
return
Space::
{
MouseGetPos,coordx, coordy
PixelGetColor,color,%coordx%,%coordy%
MsgBox,,Result, Color: %color%`nPosition: (%coordx%.%coordy%)
return
}
GuiClose:
ExitApp
|
Let's go into the code:
-------------------------------------------------------
Code:
; getting coords and color
Gui, Show , w250 h50, Info
; only a text
Gui, Add, Text, x10 y12 Left, Press <SPACE> to pick up color and position
return
Creating the window with the title
Info and then a
Text to tell the user what to do.
-------------------------------------------------------
Code:
Space::
{
MouseGetPos,coordx, coordy
PixelGetColor,color,%coordx%,%coordy%
MsgBox,,Result, Color: %color%`nPosition: (%coordx%.%coordy%)
return
}
Here is the important code of the sample, first we are creatning a HotKey using the
Space bar, inside the brackets is the action to do after pressing the space.
Let see line by line:
MouseGetPos,coordx, coordy
Here we are calling the function
MouseGetPos (get position right?), since the result will have 2 outputs (x position and y position) we need 2 variables to save the result,
coordx and
coordy are those variables, you can name them the way you want, the basic structure is:
MouseGetPos,VARIABLE_FOR_X_POS, VARIABLE_FOR_Y_POS
We are going to need those positions for the next function.
PixelGetColor,color,%coordx%,%coordy%
Here we are calling the function
PixelGetColor, the result will be saved into the variable
color, in order to use this function we have to give a position where the program should get the color, in this case we are using the variables
coordx and
coordy so it will pick the color on the same positions where the mouse is.
The structure is:
PixelGetColor,VARIABLE_TO_SAVE_THE_RESULT, XPOSITION, YPOSITION
And after all that we finally have 3 values saved into 3 variables,
coordx: here is the x position of the mouse on the moment we press Space
coordy: here is the y position of the mouse
color: here is the color picked from the position coordx, coordy
So what we do is send a message box with the results ^^
The code
´n is to create a new line.
-------------------------------------------------------
Code:
GuiClose:
ExitApp
An easy one ^^
-------------------------------------------------------
Alright guys, this one is pretty useful, if you want to create bots or macros ull probably work a lot with pixel colors so try to understand this very well =D
And as I always say, check the
AutoHotKey Help File for more info about the commands and options.
I think tomorrow i'll make a sample on how to search for a pixel color on the screen (main function for pixel autoattackers).