AutoIt – Pixel_Pos

Table of Contents

Code

				
					#Region PixelGet
; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:       English
; Description:	Give Pixel Location on Desktop or active window
;
; ------------------------------------------------------------------------------
;					WORK IN PROGRESS
;===============================================================================
;
;	HotKeys:		End - Quits programm
;					Q - Save Values to Clipboard
;		 			R - Set Aspect ratio to active Window
;					E - Set CoordMode
;
;===============================================================================
#EndRegion PixelGet

#include-once
#include <MsgBoxConstants.au3>

DllCall("User32.dll", "bool", "SetProcessDPIAware")    ;ResultionScaleFix

AutoItSetOption("MouseCoordMode", "2")              ;MouseCoordsMode-Client 0=full active window, 1=fullscreen, 2=active window
AutoItSetOption("PixelCoordMode", "2")              ;PixelCoordsMode-Client

;===============================================================================

HotKeySet('{F1}', 'Clipboard')
HotKeySet('{F2}', 'GetResolution')
HotKeySet('{F3}', 'CordMode')
HotKeySet('{F5}', 'Quit')

;===============================================================================

Global $Mouse_X
Global $Mouse_Y
Global $Mouse_Color
Global $Window_Width
Global $Window_Height
Global $aTitle
Global $CordMode = 2

;===============================================================================

OnAutoItExitRegister(Quit)
CordMode()
GetResolution()

While 1
	Sleep(100)
	GetPos()
	GetColor()
	ToolTip("Active: " & $aTitle & " X: " & $Mouse_X & " Y: " & $Mouse_Y & " C: #" & $Mouse_Color, 0, 0)
WEnd

Func GetResolution()
	$aTitle = _WinGetClass(WinGetTitle("[ACTIVE]"))
	Local $aPos = WinGetPos("[ACTIVE]")
	$Window_Width = $aPos[2]
	$Window_Height = $aPos[3]
EndFunc   ;==>GetResolution

Func GetPos()
	Local $mpos = MouseGetPos()
	$Mouse_X = $mpos[0]
	$Mouse_Y = $mpos[1]
EndFunc   ;==>GetPos

Func GetColor()
	$Mouse_Color = Hex(PixelGetColor($Mouse_X, $Mouse_Y), 6)
EndFunc   ;==>GetColor

Func Clipboard()
	Local $r = _GCD($Window_Width, $Window_Height)
	Local $aSave = Naming()
	ClipPut("Name:       " & $aSave & @CRLF & _
			"X:          " & $Mouse_X & @CRLF & _
			"Y:          " & $Mouse_Y & @CRLF & _
			"C:          #" & $Mouse_Color & @CRLF & _
			"Dimensions: " & $Window_Width & "x" & $Window_Height & @CRLF & _
			"Gcd:        " & $r & @CRLF & _
			"Aspect:     " & $Window_Width / $r & ":" & $Window_Height / $r & @CRLF)
EndFunc   ;==>Clipboard

Func Naming()
	Local $sAnswer = InputBox("Save", "X:          " & $Mouse_X & @CRLF & _
			"Y:          " & $Mouse_Y & @CRLF & _
			"C:          #" & $Mouse_Color & @CRLF, "Name", "", -1, -1)
	Return $sAnswer
EndFunc   ;==>Naming

Func CordMode()
	AutoItSetOption("MouseCoordMode", $CordMode)
	AutoItSetOption("PixelCoordMode", $CordMode)
	ConsoleWrite("Mode: " & $CordMode & @CRLF)
	If $CordMode >= 2 Then
		$CordMode = 0
	Else
		$CordMode += 1
	EndIf
EndFunc   ;==>CordMode

Func Quit()
	ConsoleWrite("Exit Program" & @CRLF)
	Exit
EndFunc   ;==>Quit

Func _GCD($a, $b)
	If $b = 0 Then Return $a
	Return _GCD($b, Mod($a, $b))
EndFunc   ;==>_GCD

Func _WinGetClass($hWnd)
	If IsHWnd($hWnd) = 0 And WinExists($hWnd) Then $hWnd = WinGetHandle($hWnd)
	Local $aGCNDLL = DllCall('User32.dll', 'int', 'GetClassName', 'hwnd', $hWnd, 'str', '', 'int', 4095)
	If @error = 0 Then Return $aGCNDLL[2]
	Return SetError(1, 0, '')
EndFunc   ;==>_WinGetClass
				
			

Leave a Reply