Page 1 of 1

PixelSearch with visual cue

Posted: 18 Jun 2019, 13:10
by PipeDreams
Here is a fun little script I made to help me understand PixelSearch a bit better. I thought it might help other as well.
PixelSearch.gif
PixelSearch.gif (175.23 KiB) Viewed 548 times

Code: Select all

;<===================================== PixelSearch with visual cue =====================================>
#SingleInstance Force
Process, Priority, , Above Normal
SetControlDelay, -1
SetBatchLines, -1
SetWinDelay, -1
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
CoordMode, ToolTip, Screen
MouseMove, (A_ScreenWidth/2), (A_ScreenHeight/2)
IfNotExist, %USERPROFILE%\Downloads\Test_Pic.jpg
{	UrlDownloadToFile, https://www.autohotkey.com/boards/download/file.php?id=7789, %USERPROFILE%\Downloads\Test_Pic.jpg
} SplashImage, %USERPROFILE%\Downloads\Test_Pic.jpg, B FS18, Teast Image
Loop,
{	PixelSearch, X, Y, X1, Y1, X2, Y2, 0x000000, 0, RGB Fast
	If (!ErrorLevel)
	{	FrameColor := "Lime"
		GoSub, Box
		ToolTip, Pixel Found, (X-40), (Y+57), 1
	} Else,
	{	FrameColor := "Red"
		GoSub, Box
		ToolTip, Searching, (X-30), (Y+57), 1
}	} Return
Box:
{	WinGetPos,,, WindowWidth, WindowHeight, %WinTitle%
	MouseGetPos, X, Y
	;	Uupper Left Corner		|	Lower Right Corner
	;	Left		   Top		|	Right		Bottom
	X1 := (X-50), Y1 := (Y-50), X2 := (X+50), Y2 := (Y+50) ;Adjust The Size of The Search Area/Box.
	FrameThickness := (1), FrameWidth := (X2-X1), FrameHeight := (Y2-Y1)
	Gui, 1: Margin, %FrameThickness%, %FrameThickness%
	Gui, 1: Color, %FrameColor%
	Gui, 1: Add, Text, W%FrameWidth% H%FrameHeight% 0x6
	Gui, 1: -Caption +AlwaysOnTop +ToolWindow +LastFound
	Gui, 1: Show, NoActivate, Gui1
	WinSet, TransColor, White
	WinMove, %WinTitle%,, (X-(WindowWidth/2)), (Y-(WindowHeight/2))
} Return
~Esc::ExitApp
;<================================================= END =================================================>