PixelSearch with visual cue

Get help with using AutoHotkey and its commands and hotkeys
User avatar
PipeDreams
Posts: 121
Joined: 19 Dec 2015, 00:20

PixelSearch with visual cue

18 Jun 2019, 12:59

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
PixelSearch.gif (175.23 KiB) Viewed 206 times

Code: Select all

#SingleInstance Force
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
CoordMode, ToolTip
MouseMove, (A_ScreenWidth/2), (A_ScreenHeight/2)
UrlDownloadToFile, https://www.autohotkey.com/boards/download/file.php?id=7457, %USERPROFILE%\Downloads\Testerpic.jpg
SplashImage, %USERPROFILE%\Downloads\Testerpic.jpg, B FS18, Teast Image
Text1 = Black Pixel Found
Text2 = Searching Black Pixel
Loop,
{	WinGetPos,,, WindowWidth, WindowHeight, %WinTitle%
	MouseGetPos, X, Y
	;Uupper Left Corner			Lower Right Corner
	;Width1		  Height1		Width2		  Height2
	X1 := (X-50), Y1 := (Y-50), X2 := (X+50), Y2 := (Y+50) ;Adjust the size
	;For the Gui
	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))
	PixelSearch, X, Y, X1, Y1, X2, Y2, ("0x000000"), BGR, 0, Fast
	If (!ErrorLevel)
	{	FrameColor := ("Lime")
		MouseGetPos, X, Y
		ToolTip, %Text1%, (X-52), (Y+57), 1
	} Else,
	{	FrameColor := ("Red")
		MouseGetPos, X, Y
		ToolTip, %Text2%, (X-58), (Y+57), 1
}	} Return
~Esc::ExitApp
Testerpic.jpg
Testerpic.jpg
Testerpic.jpg (3.71 KiB) Viewed 206 times
Hellbent
Posts: 755
Joined: 23 Sep 2017, 13:34

Re: PixelSearch with visual cue

18 Jun 2019, 14:51

Very cool PipeDreams!!

I made some small tweaks to get a bit more performance out of it.

Code: Select all

#SingleInstance Force
SetBatchLines,-1
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen

Gui,1:+AlwaysOnTop -Caption +LastFound ToolWindow -DPIScale
Gui,1:Color,Red
Gui,1:Font,cBlack s8 Bold
Gui,1:Add,Text,x1 y101 w101 h20 Center 0x200 vText,Searching...
Gui,1:Show,w101 h121 
Winset,TransColor,123456
Gui,2:-Caption +Parent1
Gui,2:Color,123456
Gui,2:Show,x1 y1 w99 h99
RunSearch()
return
*ESC::
	ExitApp

RunSearch(){
	Color:="0x000000"
	Variation:=0
	Loop	{
		MouseGetPos,x,y
		Gui,1:Show,% "x" x-50 " y" y-50 " NA"
		PixelSearch,px,py,x-49,y-49,x+49,y+49,Color,Variation,Fast|RGB
		if(!ErrorLevel&&Old!=ErrorLevel){
				Old:=ErrorLevel
				Gui,1:Color,Lime
				GuiControl,1:,Text,!!! Found !!!
		}else if(ErrorLevel&&Old!=ErrorLevel){
				Old:=ErrorLevel
				Gui,1:Color,Red
				GuiControl,1:,Text,Searching...
		}
	}
}

Once again, very cool idea. :thumbup:

Return to “Ask For Help”

Who is online

Users browsing this forum: asad41163, Bing [Bot], cainxabel, guiguintx, Jovannb, TAC109 and 195 guests