Storing distinct colors during a click and drag
Posted: 23 Apr 2018, 21:27
Hey guys, I'd like to be able to easily pick up colors from vector palettes like this one by dragging over them while holding a mouse button:
I thought this would be easy but I'm having trouble with it, and keep getting the same color spammed despite a few different ways of trying. My current code:
If you run this, you'll see that it fills up each 3 slots with the first color it encounters but I'm confused by this because those conditions shouldn't be met if that color is equal to the previous. The errCount variable is to try and pick up distinct colors and avoid anti-aliasing of borders though I think it might be complicating things, is there anything obviously wrong with the code here?
I'm trying to store up to 3 color values when I click-drag over them excluding the background color, can this be better done?
I thought this would be easy but I'm having trouble with it, and keep getting the same color spammed despite a few different ways of trying. My current code:
Code: Select all
#NoEnv
#SingleInstance, Force
SetWorkingDir %A_ScriptDir%
SetTimer, mouseTrack, 20
mouseTrack:
MouseGetPos, vCurX, vCurY
Return
!#RButton::
colorScan := "Start"
errCount = 0
newColor1 := "", newColor2 := "", newColor3 := ""
originX := vCurX, originY := vCurY
SetTimer, WhileHolding, 20
PixelGetColor, originColor, originX, originY, RGB
Return
WhileHolding:
PixelGetColor, newColor, vCurX, vCurY, RGB
While (newColor != originColor) {
If (colorScan = "Done")
Break
++errCount
If (errCount > 5) {
errCount = 0
If ((newColor2 != "") && (newColor3 != newColor2)) {
newColor3 := newColor
colorScan := "Done"
} Else If (!(newColor2 != "") && (newColor2 != newColor1)) {
newColor2 := newColor
} Else {
newColor1 := newColor
}
}
}
ToolTip % errCount "`r`n" originColor "`r`n" newColor "`r`n" "1:" newColor1 "`r`n" "2:" newColor2 "`r`n" "3:" newColor3 "`r`n" colorScan
Return
!#RButton Up::
SetTimer, WhileHolding, Off
ToolTip
Return
I'm trying to store up to 3 color values when I click-drag over them excluding the background color, can this be better done?