The x-, y- and color values, can I see in AHK-Window spy.
But, I find it difficult to read where the mouse points.
Because of this problem, I have written a small program to check colors in one area.
The results can be advantageous analyzed in e.g. Calc or Excel
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
#SingleInstance Force
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Result file
FileName = ColorArea.txt
IfExist %FileName%
FileDelete %FileName%
; Area to check
CoordMode Pixel, Client
xPos1 = 325 ; Upper left corner (Client value)
yPos1 = 6
xPos2 = 350 ; Lower right corner (Client value)
yPos2 = 30
MsgBox 64, Rad %A_LineNumber% -> %A_ScriptName%,
(LTrim Join
The controlled area. (Mode = Client)`n
(the area values is changed in this AHK-program)`n
- - Upper left`n
`txPos = %xPos1% `n
`tyPos = %yPos1% `n`n
- - Lower right`n
`txPos = %xPos2%`n
`tyPos = %yPos2%`n`n
Activate the desired window/program, after the button "OK!" is pressed. `n
After the button "OK" is pressed, This program is then wait 5 seconds, `n
before the colorcheck is begun.
)
Sleep 5000
; Adjust for headlines
xPos := xPos1
xStep := xPos2 + 1 - xPos1
yPos := yPos1
yStep := yPos2 + 1 - yPos1
xPos1 = %xPos% ; Keep the original x-pos
Loop % xStep + 1
{ If A_Index = 1 ; Add an empty column
{ Result := A_Space ";"
EnvSub xPos, 1
}
else
{ EnvAdd xPos, 1 ; Remove the last "semicolon"
If A_Index <= %xStep%
Result .= xPos ";"
else
Result .= xPos "`n"
}
}
xPos = %xPos1% ; Begin again
yPos1 = %yPos% ; Keep the original y-pos
Loop %yStep%
{ Loop % xStep + 1
{ If A_Index = 1 ; The Y-value
{ Result .= yPos ";"
EnvSub xPos, 1 ; Remove the first column
}
else
{ EnvAdd xPos, 1 ; Remove the last "semicolon"
If A_Index <= %xStep%
{ ColorName := ColorName(xPos, yPos) ; Give the color of a position a name
Result .= ColorName ";"
}
else
{ ColorName := ColorName(xPos, yPos) ; Give the color of a position a name
Result .= ColorName "`n"
}
; MsgBox 64, Rad %A_LineNumber% -> %A_ScriptName%, xPos = %xPos% `nyPos = %yPos% `nColorName = %ColorName%
}
}
EnvAdd yPos, 1
; MsgBox 64, Rad %A_LineNumber% -> %A_ScriptName%, xPos = %xPos% `nyPos = %yPos% `n`n%Result%
xPos := xPos1
}
FileAppend %Result%, %FileName%
MsgBox 64, Rad %A_LineNumber% -> %A_ScriptName%, Logfil .: %FileName% `n`nThe area ColorCheck is Ready!
ExitApp
ColorName(xPos, yPos) ; Give the RGB-color a name
{ ; MsgBox 64, Rad %A_LineNumber% -> %A_ScriptName%, OutName = %OutName% `nPixColor = %PixColor% `nxPos = %xPos% `nyPos = %yPos%
CoordMode Pixel, Client
PixelGetColor PixColor, %xPos%, %yPos%, RGB ; Read the color (RGB) in a determined position
OutName = %PixColor%
; MsgBox 64, Rad %A_LineNumber% -> %A_ScriptName%, OutName = %OutName% `nPixColor = %PixColor% `nxPos = %xPos% `nyPos = %yPos%
If PixColor = 0x000000
OutName := "Black"
If PixColor = 0xFFFFFF
OutName := "White"
If PixColor = 0x0078D7
OutName := "MarkBlue"
If PixColor = 0xA8C9EA
OutName := "LightBlue"
If PixColor = 0xF0F0F0
OutName := "LightGray"
If PixColor = 0xF0AB60
OutName := "Orange"
If PixColor = 0xA0A0A0
OutName := "Gray"
If (PixColor = 0x40C040) or (PixColor = 0x00FF00)
OutName := "Green"
If PixColor = 0x008000
OutName := "DarkGreen1"
If PixColor = 0x005600
OutName := "DarkGreen"
If PixColor = 0xFF0000
OutName := "Red"
If PixColor = 0xA7C8E9
OutName = "LightPurple"
If PixColor = 0xA7C7E8
OutName = "LightPurple"
If PixColor = 0xA6C7E7
OutName = "LightPurple"
If PixColor = 0xA5C6E6
OutName = "LightPurple"
If PixColor = 0xA5C5E6
OutName = "LightPurple"
If PixColor = 0xA6C7E8
OutName = "LightPurple"
If PixColor = 0xA6C6E7
OutName = "LightPurple"
If PixColor = 0xA5C5E5
OutName = "LightPurple"
; MsgBox 64, Rad %A_LineNumber% -> %A_ScriptName%, OutName = %OutName% `nPixColor = %PixColor% `nxPos = %xPos% `nyPos = %yPos%
Return %OutName%
}
However, different computers (depending on resolution, etc.) provide different color values in the analysis.
The variations are not large, but enough to not match.
For example, with my eye is both 0xFFFFFF, and 0xFCFFFF an white color.
The program above give me the hex-color name, and I can give the color an easier name,
and give many HEX-colors the same name.
But my color names can have many, many, variations of hex colors,
and I do not want to write huge if-instructions or build complicated loops for each color.
Is there any alternative?
Which way is easiest to name a variety of adjacent colors to the same name?
(This makes it easier to analyze the colors in areas)
Then I want to create a function that checks the color in a selected point.
Something like this .:
Code: Select all
Result := ColorCheck(xPos,yPos,"White")
If Result = Yes
Do....
ColorCheck(xPos,yPos,Color)
{ ....
Return %Result% ; Return Yes och HEX-Colorname (No)
}