PixelSearch & PixelGetColor with visual cues & multiple clipboard output tool.

Post your working scripts, libraries and tools
User avatar
PipeDreams
Posts: 117
Joined: 19 Dec 2015, 00:20

PixelSearch & PixelGetColor with visual cues & multiple clipboard output tool.

10 Jul 2019, 16:51

This is a tool I made for locating pixels in a game, for when I am building other scripts that use the PixelGetColor and PixelSearch command.

Hold RButton to get a visual representation of a single pixel under the mouse pointer, or Double click and hold the Right Mouse Button on the second click to get a visual representation of the general area you want to use the PixelSearch command to look for.

The script will save the color to your clipboard upon releasing Right Click in either case.

Then just paste into the script that you are working on . ;)

Single click paste output preview:

Code: Select all

	;PixelGetColor, 0xD4AF55, 1102, 400, RGB Fast
Double click paste output preview:

Code: Select all

	;PixelSearch, X, Y, 1496, 637, 1719, 891, ("0xE1EBF2"), 60, RGB, Fast
	;Color1	=	0xE1EBF2 On KeyDown
	;Color2	=	0xE1EBF2 On KeyUp
	;AveragedColor = 0xE1EBF2 On KeyUp
Here is the tool:

Code: Select all


;												<+++PixelSearchFilder+++>
#SingleInstance Force
Process, Priority, , Above Normal
SetControlDelay, -1
SetBatchLines, -1
SetWinDelay, -1
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
CoordMode, ToolTip, Screen
RButton::																	;RClick Hotkey
{	Gui, 1: Destroy															;Removes last instance of Gui, 1:
	If ((A_TimeSincePriorHotkey < 400) AND (A_TimeSincePriorHotkey !=-1))	;Double Click RButton and Hold on 2nd Click.
	{	Gui, 2: Destroy														;Removes last instance of Gui, 2:
		MouseGetPos, xPos, yPos
		X1 := (xPos), Y1 := (yPos)
		PixelGetColor, Color, xPos, yPos, RGB, Fast
		Color1 := Color
		Gui, 2: -Caption +AlwaysOnTop +ToolWindow +LastFound
		Gui, 2: Color, Lime
		Gui, 2: Show, NA x%xPos% y%yPos%, Gui2 								;StartPoint
		SetTimer, ReSize, 1
			KeyWait, RButton												;Waits for HotKey to be released.
				SetTimer, ReSize, OFF
				GoSub, RemoveToolTip
				If (InitialClick)											;To cut down ToolTip flickering.
				{	InitialClick:= !InitialClick
				} FrameColor := Avg, FrameThickness := (1), FrameWidth := (X2-2), FrameHeight := (Y2-2) 
				;FrameWidth & FrameHeight Subtraction Values Needs To Be Bouble That of FrameThickness Value. 
				;Example FrameThickness := (2), FrameWidth := (X2-4), FrameHeight := (Y2-4) and so on... 
				Gui, 2: Margin, %FrameThickness%, %FrameThickness%
				Gui, 2: Color, %FrameColor%
				Gui, 2: Add, Text, W%FrameWidth% H%FrameHeight% 0x6
				Gui, 2: +Alwaysontop -Caption +E0x20
				WinSet, TransColor, White, Gui2
	} Else,																	;Hold HotKey & Wait.
	{	KeyWait, RButton, T0.1
		If (ErrorLevel)
		{	While, (GetKeyState("RButton", "P"))
			{	MouseGetPos, xPos, yPos
				;MouseMove, 615, 902										;Set mouse location to get pixel from.
				PixelGetColor, Color, xPos, yPos, RGB, Fast
				Clipboard := ";PixelGetColor, "Color "," " "xPos ", "yPos ", RGB, Fast" 
				;PasetOutputPreview = ;PixelGetColor, 0xD4AF55, 1102, 400, RGB Fast
				Gui, 1: -Caption +AlwaysOnTop +ToolWindow +LastFound
				Gui, 1: Color, %Color%
				If (!InitialClick)
				{	If (!GUI1)
					{	GUI1 := !GUI1			
					} GoSub, ToolTipStuff									;To cut down the ToolTip flickering.		
				} Else, 
				{	MouseGetPos, xPos2, yPos2
					If ((xPos<>xPos2) OR (yPos<>yPos2))						;When moving mouse in any direction
					{	GoSub, ToolTipStuff
					} ToolTip, %Clipboard%, %X5%, %Y5% 
					Gui, 1: Show, NA x%X4% y%Y4% h50 w50, Gui1
			}	} KeyWait, RButton
			GoSub, RemoveToolTip
			If (GUI1)
			{	GUI1 := !GUI1													
			} If (InitialClick)
			{	InitialClick := !InitialClick
}	}	}	} Return
ReSize:											;<===Mouse&GuiStuff===>
{	MouseGetPos, xPos, yPos
	X2 := (xPos - X1), Y2 := (yPos - Y1)
	X3 := (xPos + 1), Y3 := (yPos + 1) 										;To Stop Averaged Color Preview flickering for Left & Up.
	If ((X2 > 0) AND (Y2 < 0))											;When moving mouse Up & Right
	{	X2 := (X2 * 1), Y2 := (Y2 * -1)
		A := (X1), B := (yPos), C := (xPos-2), D := (Y1-2)					;x1, y2, x2, y1 ;Up & Right
		Gui, 2: Show, NA H%Y2% W%X2% Y%yPos%, Gui2							;EndPoint
	} Else,
	If ((X2 < 0) AND (Y2 < 0))											;When moving mouse Up & Left
	{	X2 := (X2 * -1), Y2 := (Y2 * -1)
		A := (xPos+1), B := (yPos+1), C := (X1-2), D := (Y1-2)				;x2, y2, x1, y1 ;Up & Left
		Gui, 2: Show, NA H%Y2% W%X2% X%X3% Y%Y3%, Gui2						;EndPoint
	} Else, 
	If ((X2 > 0) AND (Y2 > 0))											;When moving mouse Down & Right
	{	A := (X1), B := (Y1), C := (xPos-2), D := (yPos-2)					;x1, y1, x2, y2 ;Down & Right
		Gui, 2: Show, NA H%Y2% W%X2%, Gui2									;EndPoint
	} Else,
	If ((X2 < 0) AND (Y2 > 0))											;When moving mouse Down & Left
	{	X2 := (X2 * -1), Y2 := (Y2 * 1)
		A := (xPos), B := (Y1), C := (X1-2), D := (yPos-2)					;x2, y1, x1, y2 ;Down & Left
		Gui, 2: Show, NA H%Y2% W%X2% X%xPos%, Gui2							;EndPoint
	} ;X=Horizontal Y=Vertical
	;x1, y2, x2, y1 ;Up & Right	----	A := X1, B := yPos, C := xPos, D := Y1
	;x2, y2, x1, y1 ;Up & Left	----	A := xPos, B := yPos, C := X1, D := Y1
	;x1, y1, x2, y2 ;Down & Right --	A := X1, B := Y1, C := xPos, D := yPos
	;x2, y1, x1, y2 ;Down & Left ---	A := xPos, B := Y1, C := X1, D := yPos
	PixelGetColor, Color, xPos, yPos, RGB, Fast
	Color2 := Color
	SetFormat, Integer, Hex
	Avg := (Color1 + Color2) * 0.5 											;Some Math to average colors 1 & 2
	Gui, 2: Color, %Avg%													;Averaged Color Preview
	Clipboard := ";PixelSearch, X, Y, "A ", "B ", "C ", "D ", ("""Ceil(Avg)"""), 60, RGB, Fast`n;Color1	=	"Color1 " On KeyDown`n;Color2	=	"Color2 " On KeyUp`n;AveragedColor = "Ceil(Avg) " On KeyUp"
	;Clipboard := "X1:="A ", Y1:="B ", X2:="C ", Y2:="D ""
	/*											<===pasetOutputPreview===>
	;PixelSearch, X, Y, 1496, 637, 1719, 891, ("0xE1EBF2"), 60, RGB, Fast
	;Color1	=	0xE1EBF2 On KeyDown
	;Color2	=	0xE1EBF2 On KeyUp
	;AveragedColor = 0xE1EBF2 On KeyUp
	*/ ToolTip, %Clipboard%, %X5%, %Y5% 
	If (!InitialClick)
	{	GoSub, ToolTipStuff
	} Else,
	{	MouseGetPos, xPos2, yPos2
		If ((xPos<>xPos2) OR (yPos<>yPos2))
		{	GoSub, ToolTipStuff
}	}	} Return
ToolTipStuff:
{	If ((xPos > A_ScreenWidth/2) AND (yPos < A_ScreenHeight/2))			;When moving mouse UpRight
	{	X5 := 0, Y5 := 1070													;Send ToolTip to the BottomLeft
		If (GUI1)
		{	X4 := (xPos - 100), Y4 := (yPos + 100)							;Send Window to BottomLeft of Mouse
	}	} Else,
	If ((xPos < A_ScreenWidth/2) AND (yPos < A_ScreenHeight/2))			;When moving mouse UpLeft
	{	X5 := 1919, Y5 := 1079												;Send ToolTip to the BottomRight
		If (GUI1)
		{	X4 := (xPos + 100), Y4 := (yPos + 100)							;Send Window to BottomRight of Mouse
	}	} Else, 
	If ((xPos < A_ScreenWidth/2) AND (yPos > A_ScreenHeight/2))			;When moving mouse DownLeft
	{	X5 := 1919, Y5 := 1													;Send ToolTip to the TopRight
		If (GUI1)
		{	X4 := (xPos + 100), (Y4 := yPos - 100)							;Send Window to TopRight of Mouse
	}	} Else, 
	If ((xPos > A_ScreenWidth/2) AND (yPos > A_ScreenHeight/2))			;When moving mouse DownRight
	{	X5 := 0, Y5 := 0 													;Send ToolTip to the TopLeft
		If (GUI1)
		{	X4 := (xPos - 100), Y4 := (yPos - 100)							;Send Window to TopLeft of Mouse
	}	} If !InitialClick
	{	InitialClick:= !InitialClick
		ToolTip, %Clipboard%, %X5%, %Y5% 
		Sleep, 100
	} WinSet, Trans, 200, ahk_class tooltips_class32
	If (!GUI1)
	{	WinSet, Transparent, 100, Gui2
}	} Return
RemoveToolTip:
{	Gui, 1: Destroy
	ToolTip
} Return
~Esc::ExitApp																;Kills the Script

Return to “Scripts and Functions”

Who is online

Users browsing this forum: dammtools, gwarble and 23 guests