PixelChecksum Coordinates.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

PixelChecksum Coordinates.

15 Sep 2021, 23:52

Hi everyone

I found this script online and its working very nicely.

It monitors for any change that takes place on the screen.

I want to define the search area

Code: Select all

^d::
ChkSum := PixelChecksum( 0,0,32,32 )

While % ( ChkSum = PixelChecksum( 0,0,32,32 ) )
   Sleep, 100
MsgBox, Screen Region Change Detected!



PixelCheckSum( X, Y, W, H, Title := "" ) { ;               By SKAN,   http://goo.gl/X5dfvn
;                                                          CD:08/Jun/2009 | MD:01/Sep/2014

  Static DIBSECTION, SRCCOPY := 0x00CC0020, CAPTUREBLT := 0x40000000, BPP := 32
  Local hWnd, hDC, mDC, hBM, oBM, nSize, pBITMAPINFOHEADER, ppvBits := 0
  
  If not VarSetCapacity( DIBSECTION )
         VarSetCapacity( DIBSECTION, 104, 0 ) 
  
  pBITMAPINFOHEADER := &DIBSECTION + ( A_PtrSize = 4 ? 24 : 32 )
  
  NumPut(  40, pBITMAPINFOHEADER +  0, "UInt"   ) 
  NumPut(   W, pBITMAPINFOHEADER +  4, "UInt"   )
  NumPut(   H, pBITMAPINFOHEADER +  8, "UInt"   )
  NumPut(   1, pBITMAPINFOHEADER + 12, "UShort" )
  NumPut( BPP, pBITMAPINFOHEADER + 14, "UShort" )

  hWnd  := WinExist( Title )
  hDC   := DllCall( "GetDC", "Ptr",hWnd, "UPtr" )
  mDC   := DllCall( "CreateCompatibleDC", UInt,hDC, "UPtr" )

  hBM   := DllCall( "CreateDIBSection", "Ptr", mDC, "Ptr", pBITMAPINFOHEADER, "Int",0
                                      , "PtrP",ppvBits, "Ptr",0, "Int",0, "UPtr" )
  
  oBM   := DllCall( "SelectObject", "Ptr",mDC, "Ptr",hBM, "UPtr" )
  
  DllCall( "BitBlt", "Ptr",mDC, "Int",0, "Int",0, "Int",W, "Int",H, "Ptr",hDC
                   , "Int",X, "Int",Y, "UInt",SRCCOPY | CAPTUREBLT )

  DllCall( "SelectObject", "Ptr",mDC, "Ptr",oBM )
  DllCall( "DeleteDC",  "Ptr",mDC )
  DllCall( "ReleaseDC", "Ptr",hWnd, "Ptr",hDC )

  DllCall( "GetObject", "Ptr",hBM, "Int",( A_PtrSize = 4 ? 84 : 104 ), "Ptr",&DIBSECTION )
  nSize := NumGet( pBITMAPINFOHEADER + 20, "UInt" ) 
  
Return DllCall( "NTDLL\RtlComputeCrc32", "UInt",0, "Ptr",ppvBits, "UInt",nSize, "UInt" )
     , DllCall( "DeleteObject", "Ptr",hBM )    
}

I tried changing the values in the lines - 2,4,10 but it didn't work
(I don't even know if those are the correct parameters that need to be changed.)

Can someone please point out where I need to enter the coordinates ?

(For the sake of clarity) The area that needs to be monitored is within the blue rectangle (ref img)


Regards.
Attachments
Pixel Change.png
Pixel Change.png (58.72 KiB) Viewed 1093 times
User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: PixelChecksum Coordinates.

16 Sep 2021, 00:07

Line 27


Code: Select all

numpad1::
	ToolTip, % hWnd  := WinExist( Title )
	return
Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: PixelChecksum Coordinates.

16 Sep 2021, 00:38

Hallo,
better use the modern version of PixelChecksum(): ScrCmp()
viewtopic.php?t=82812
SpeedMaster added the region selector from jeeswg to define the search area.
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: PixelChecksum Coordinates.

16 Sep 2021, 02:03

Hellbent wrote:
16 Sep 2021, 00:07
Line 27


Code: Select all

numpad1::
	ToolTip, % hWnd  := WinExist( Title )
	return
I am confused.

How will that enable the entry of x y coordinates ?
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: PixelChecksum Coordinates.

16 Sep 2021, 02:39

Rohwedder wrote:
16 Sep 2021, 00:38
Hallo,
better use the modern version of PixelChecksum(): ScrCmp()
viewtopic.php?t=82812
SpeedMaster added the region selector from jeeswg to define the search area.
I didn't see the speedmaster part.

I will try once more
Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: PixelChecksum Coordinates.

16 Sep 2021, 02:41

Hallo,
(based of SpeedMaster example)
use Hotkey Win + LButton to define the search area:

Code: Select all

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

;note: 'CoordMode, Mouse, Screen' must be used in the auto-execute section

#LButton::
InputRect(vX1, vY1, vX2, vY2)
vW := vX2-vX1, vH := vY2-vY1
if (vInputRectState = -1)
	return
sleep, 200
ScrCmp(vX1, vY1, vW, vH)
MsgBox,% "Screen Region Change Detected!`nX: " A_Args.ScrCmp.CX " Y: " A_Args.ScrCmp.CY
Return
;==================================================
;thx jeeswg
;https://www.autohotkey.com/boards/viewtopic.php?t=42810

;based on LetUserSelectRect by Lexikos:
;LetUserSelectRect - select a portion of the screen - Scripts and Functions - AutoHotkey Community
;https://autohotkey.com/board/topic/45921-letuserselectrect-select-a-portion-of-the-screen/

;note: 'CoordMode, Mouse, Screen' must be used in the auto-execute section

;e.g.
;InputRect(vWinX, vWinY, vWinR, vWinB)
;vWinW := vWinR-vWinX, vWinH := vWinB-vWinY
;if (vInputRectState = -1)
;	return

InputRect(ByRef vX1, ByRef vY1, ByRef vX2, ByRef vY2)
{
	global vInputRectState := 0
	DetectHiddenWindows, On
	Gui, 1: -Caption +ToolWindow +AlwaysOnTop +hWndhGuiSel
	Gui, 1: Color, Red
	WinSet, Transparent, 128, % "ahk_id " hGuiSel
	Hotkey, *LButton, InputRect_Return, On
	Hotkey, *RButton, InputRect_End, On
	Hotkey, Esc, InputRect_End, On
	KeyWait, LButton, D
	MouseGetPos, vX0, vY0
	SetTimer, InputRect_Update, 10
	KeyWait, LButton
	Hotkey, *LButton, Off
	Hotkey, Esc, InputRect_End, Off
	SetTimer, InputRect_Update, Off
	Gui, 1: Destroy
	return

	InputRect_Update:
	if !vInputRectState
	{
		MouseGetPos, vX, vY
		(vX < vX0) ? (vX1 := vX, vX2 := vX0) : (vX1 := vX0, vX2 := vX)
		(vY < vY0) ? (vY1 := vY, vY2 := vY0) : (vY1 := vY0, vY2 := vY)
		Gui, 1:Show, % "NA x" vX1 " y" vY1 " w" (vX2-vX1) " h" (vY2-vY1)
		return
	}
	vInputRectState := 1

	InputRect_End:
	if !vInputRectState
		vInputRectState := -1
	Hotkey, *LButton, Off
	Hotkey, *RButton, Off
	Hotkey, Esc, Off
	SetTimer, InputRect_Update, Off
	Gui, 1: Destroy

	InputRect_Return:
	return
}

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

ScrCmp( X, Y, W, H, Hwnd:=0x0, Sleep* )  {                                        ; v0.66 By SKAN on D3B3/D3B6 @ tiny.cc/scrcmp
Local
Global A_Args
  Sleep[1] := Sleep[1]="" ? 100 : Format("{:d}", Sleep[1])
  Sleep[2] := Sleep[2]="" ? 100 : Format("{:d}", Sleep[2])

  VarSetCapacity(BITMAPINFO, 40, 0)
  NumPut(32, NumPut(1, NumPut(0-H*2, NumPut(W, NumPut(40,BITMAPINFO,"Int"),"Int"),"Int"),"Short"),"Short")

  hBM := DllCall("Gdi32.dll\CreateDIBSection", "Ptr",0, "Ptr",&BITMAPINFO, "Int",0, "PtrP",pBits := 0, "Ptr",0, "Int",0, "Ptr")
  sDC := DllCall("User32.dll\GetDC", "Ptr",(Hwnd := WinExist("ahk_id" . Hwnd)), "Ptr")
  mDC := DllCall("Gdi32.dll\CreateCompatibleDC", "Ptr",sDC, "Ptr")
  DllCall("Gdi32.dll\SaveDC", "Ptr",mDC)
  DllCall("Gdi32.dll\SelectObject", "Ptr",mDC, "Ptr",hBM)
  DllCall("Gdi32.dll\BitBlt", "Ptr",mDC, "Int",0, "Int",H, "Int",W, "Int",H, "Ptr",sDC, "Int",X, "Int",Y, "Int",0x40CC0020)

  A_Args.ScrCmp := {"Wait": 1},   Bytes := W*H*4,  Count := 0
  hMod := DllCall("Kernel32.dll\LoadLibrary", "Str","ntdll.dll", "Ptr")
  While ( A_Args.ScrCmp.Wait && (Count<2) )
  {
      DllCall("Gdi32.dll\BitBlt", "Ptr",mDC, "Int",0, "Int",0, "Int",W, "Int",H, "Ptr",sDC, "Int",X, "Int",Y, "Int",0x40CC0020)
      Count := ( (Byte := DllCall("ntdll.dll\RtlCompareMemory", "Ptr",pBits, "Ptr",pBits+Bytes, "Ptr",Bytes) ) != Bytes )
               ? (Count + 1) : 0
      Sleep % (Count ? Sleep[2] : Sleep[1])
  }   Byte +=1
  DllCall("Kernel32.dll\FreeLibrary", "Ptr",hMod)

  SX := (CX := Mod((Byte-1)//4, W) + X),    SY := (CY := (Byte-1) // (W*4)   + Y)
  If (Hwnd)
    VarsetCapacity(POINT,8,0), NumPut(CX,POINT,"Int"), NumPut(CY,POINT,"Int")
  , DllCall("User32.dll\ClientToScreen", "Ptr",Hwnd, "Ptr",&POINT)
  , SX := NumGet(POINT,0,"Int"),  SY := NumGet(POINT,4,"Int")

  If (Wait := A_Args.ScrCmp.Wait)
      A_Args.ScrCmp := { "Wait":0, "CX":CX, "CY":CY, "SX":SX, "SY":SY }
  DllCall("Gdi32.dll\RestoreDC", "Ptr",mDC, "Int",-1)
  DllCall("Gdi32.dll\DeleteDC", "Ptr",mDC)
  DllCall("User32.dll\ReleaseDC", "Ptr",Hwnd, "Ptr",sDC)
  DllCall("Gdi32.dll\DeleteObject", "Ptr",hBM)
Return ( !!Wait )
}

User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: PixelChecksum Coordinates.

16 Sep 2021, 03:18

Fulminare wrote:
16 Sep 2021, 02:03

I am confused.

How will that enable the entry of x y coordinates ?
No idea what your code does. What I do know is that line 27 tries to get the hwnd of from a window to use here

Code: Select all

 hWnd  := WinExist( Title ) ;No title, No hwnd  ( 0x0 )
 hDC   := DllCall( "GetDC", "Ptr",hWnd, "UPtr" ) ;No hwnd, No hDC?
 mDC   := DllCall( "CreateCompatibleDC", UInt,hDC, "UPtr" ) ;No hDC, No mDC?
 
And you didn't give it a window.

Code: Select all

ChkSum := PixelChecksum( 0,0,32,32 ) ; NO TITLE
;and
While % ( ChkSum = PixelChecksum( 0,0,32,32 ) ) ;NO TITLE
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: PixelChecksum Coordinates.

16 Sep 2021, 03:33

Rohwedder wrote:
16 Sep 2021, 02:41
Hallo,
(based of SpeedMaster example)
use Hotkey Win + LButton to define the search area:

Code: Select all

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

;note: 'CoordMode, Mouse, Screen' must be used in the auto-execute section

#LButton::
InputRect(vX1, vY1, vX2, vY2)
vW := vX2-vX1, vH := vY2-vY1
if (vInputRectState = -1)
	return
sleep, 200
ScrCmp(vX1, vY1, vW, vH)
MsgBox,% "Screen Region Change Detected!`nX: " A_Args.ScrCmp.CX " Y: " A_Args.ScrCmp.CY
Return
;==================================================
;thx jeeswg
;https://www.autohotkey.com/boards/viewtopic.php?t=42810

;based on LetUserSelectRect by Lexikos:
;LetUserSelectRect - select a portion of the screen - Scripts and Functions - AutoHotkey Community
;https://autohotkey.com/board/topic/45921-letuserselectrect-select-a-portion-of-the-screen/

;note: 'CoordMode, Mouse, Screen' must be used in the auto-execute section

;e.g.
;InputRect(vWinX, vWinY, vWinR, vWinB)
;vWinW := vWinR-vWinX, vWinH := vWinB-vWinY
;if (vInputRectState = -1)
;	return

InputRect(ByRef vX1, ByRef vY1, ByRef vX2, ByRef vY2)
{
	global vInputRectState := 0
	DetectHiddenWindows, On
	Gui, 1: -Caption +ToolWindow +AlwaysOnTop +hWndhGuiSel
	Gui, 1: Color, Red
	WinSet, Transparent, 128, % "ahk_id " hGuiSel
	Hotkey, *LButton, InputRect_Return, On
	Hotkey, *RButton, InputRect_End, On
	Hotkey, Esc, InputRect_End, On
	KeyWait, LButton, D
	MouseGetPos, vX0, vY0
	SetTimer, InputRect_Update, 10
	KeyWait, LButton
	Hotkey, *LButton, Off
	Hotkey, Esc, InputRect_End, Off
	SetTimer, InputRect_Update, Off
	Gui, 1: Destroy
	return

	InputRect_Update:
	if !vInputRectState
	{
		MouseGetPos, vX, vY
		(vX < vX0) ? (vX1 := vX, vX2 := vX0) : (vX1 := vX0, vX2 := vX)
		(vY < vY0) ? (vY1 := vY, vY2 := vY0) : (vY1 := vY0, vY2 := vY)
		Gui, 1:Show, % "NA x" vX1 " y" vY1 " w" (vX2-vX1) " h" (vY2-vY1)
		return
	}
	vInputRectState := 1

	InputRect_End:
	if !vInputRectState
		vInputRectState := -1
	Hotkey, *LButton, Off
	Hotkey, *RButton, Off
	Hotkey, Esc, Off
	SetTimer, InputRect_Update, Off
	Gui, 1: Destroy

	InputRect_Return:
	return
}

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

ScrCmp( X, Y, W, H, Hwnd:=0x0, Sleep* )  {                                        ; v0.66 By SKAN on D3B3/D3B6 @ tiny.cc/scrcmp
Local
Global A_Args
  Sleep[1] := Sleep[1]="" ? 100 : Format("{:d}", Sleep[1])
  Sleep[2] := Sleep[2]="" ? 100 : Format("{:d}", Sleep[2])

  VarSetCapacity(BITMAPINFO, 40, 0)
  NumPut(32, NumPut(1, NumPut(0-H*2, NumPut(W, NumPut(40,BITMAPINFO,"Int"),"Int"),"Int"),"Short"),"Short")

  hBM := DllCall("Gdi32.dll\CreateDIBSection", "Ptr",0, "Ptr",&BITMAPINFO, "Int",0, "PtrP",pBits := 0, "Ptr",0, "Int",0, "Ptr")
  sDC := DllCall("User32.dll\GetDC", "Ptr",(Hwnd := WinExist("ahk_id" . Hwnd)), "Ptr")
  mDC := DllCall("Gdi32.dll\CreateCompatibleDC", "Ptr",sDC, "Ptr")
  DllCall("Gdi32.dll\SaveDC", "Ptr",mDC)
  DllCall("Gdi32.dll\SelectObject", "Ptr",mDC, "Ptr",hBM)
  DllCall("Gdi32.dll\BitBlt", "Ptr",mDC, "Int",0, "Int",H, "Int",W, "Int",H, "Ptr",sDC, "Int",X, "Int",Y, "Int",0x40CC0020)

  A_Args.ScrCmp := {"Wait": 1},   Bytes := W*H*4,  Count := 0
  hMod := DllCall("Kernel32.dll\LoadLibrary", "Str","ntdll.dll", "Ptr")
  While ( A_Args.ScrCmp.Wait && (Count<2) )
  {
      DllCall("Gdi32.dll\BitBlt", "Ptr",mDC, "Int",0, "Int",0, "Int",W, "Int",H, "Ptr",sDC, "Int",X, "Int",Y, "Int",0x40CC0020)
      Count := ( (Byte := DllCall("ntdll.dll\RtlCompareMemory", "Ptr",pBits, "Ptr",pBits+Bytes, "Ptr",Bytes) ) != Bytes )
               ? (Count + 1) : 0
      Sleep % (Count ? Sleep[2] : Sleep[1])
  }   Byte +=1
  DllCall("Kernel32.dll\FreeLibrary", "Ptr",hMod)

  SX := (CX := Mod((Byte-1)//4, W) + X),    SY := (CY := (Byte-1) // (W*4)   + Y)
  If (Hwnd)
    VarsetCapacity(POINT,8,0), NumPut(CX,POINT,"Int"), NumPut(CY,POINT,"Int")
  , DllCall("User32.dll\ClientToScreen", "Ptr",Hwnd, "Ptr",&POINT)
  , SX := NumGet(POINT,0,"Int"),  SY := NumGet(POINT,4,"Int")

  If (Wait := A_Args.ScrCmp.Wait)
      A_Args.ScrCmp := { "Wait":0, "CX":CX, "CY":CY, "SX":SX, "SY":SY }
  DllCall("Gdi32.dll\RestoreDC", "Ptr",mDC, "Int",-1)
  DllCall("Gdi32.dll\DeleteDC", "Ptr",mDC)
  DllCall("User32.dll\ReleaseDC", "Ptr",Hwnd, "Ptr",sDC)
  DllCall("Gdi32.dll\DeleteObject", "Ptr",hBM)
Return ( !!Wait )
}



Thank you. I was trying that itself. I didn't understand the windows and left click. Later it struck me that I am supposed to hold win key and drag the left mouse.

A doubt. after selecting the area, it shows a message saying that screen change has been detected , along with the coordinates of the selected screen.

I am having to select the area every time.

How to enter the coordinates displayed in the message box ?
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: PixelChecksum Coordinates.

16 Sep 2021, 03:35

Hellbent wrote:
16 Sep 2021, 03:18
Fulminare wrote:
16 Sep 2021, 02:03

I am confused.

How will that enable the entry of x y coordinates ?
No idea what your code does. What I do know is that line 27 tries to get the hwnd of from a window to use here

Code: Select all

 hWnd  := WinExist( Title ) ;No title, No hwnd  ( 0x0 )
 hDC   := DllCall( "GetDC", "Ptr",hWnd, "UPtr" ) ;No hwnd, No hDC?
 mDC   := DllCall( "CreateCompatibleDC", UInt,hDC, "UPtr" ) ;No hDC, No mDC?
 
And you didn't give it a window.

Code: Select all

ChkSum := PixelChecksum( 0,0,32,32 ) ; NO TITLE
;and
While % ( ChkSum = PixelChecksum( 0,0,32,32 ) ) ;NO TITLE
oh okay
I will try once again :)
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: PixelChecksum Coordinates.

16 Sep 2021, 04:00

I am facing a new problem.

The purpose of using this script was to trigger an action when the second person joins the zoom meeting

( the screen will then change from a full screen display of myself to the "side by side" layout showing myself and the person who has joined.)

this thing worked fine when I turned off the video.

but when I turned it on , the script naturally is considering my movements as "screen change" and the message box is getting displayed.

Please correct me,

This script works on screen shots isn't it ?

can it also be used to monitor a pixel change at a location and trigger an action ?
Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: PixelChecksum Coordinates.

16 Sep 2021, 04:02

In the above script, the call is made with ScrCmp(vX1, vY1, vW, vH) (line 14).
Display the numeric content of these 4 variables in a Msgbox and then call ScrCmp() with these 4 numbers.
Whether the script is usable for gamer? No idea, I am not a gamer.
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: PixelChecksum Coordinates.

16 Sep 2021, 06:42

You are saying that :

Code: Select all

ScrCmp(vX1, vY1, vW, vH)
is the line that stores the xy coordinates.

On selecting the screen using windows and left click, the messages box shows only the x and y values, not w and h

lets say x is 10 and y is 20


so is it :

Code: Select all

ScrCmp(vX10, vY20, vW, vH)
?

and to get the w and h it says

x1 - x2 = w

y1 - y2 = h

but the message box displays only one x and one y

where and how to get the second x and y?
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: PixelChecksum Coordinates.

16 Sep 2021, 06:58

I am trying a new approach using pixel colour change

Code: Select all

^!v::
x:= 272 ;x coordinate of pixel to check.
y:= 83 ;y coordinate of pixel to check.
targetcolor:= 0x1A1A1A ;color to be matched in hexadecimal blue-green-red (BGR) format.

Loop
{
    PixelGetColor, currentcolor, x, y
    if (currentcolor=targetcolor)
    {
        #Include C:\Users\user\Desktop\New AutoHotkey Script (4).ahk
		Send {F1}
		
		return
    }
    else
    {
        ;do something
    }
}

This is to avoid a false trigger of sort
User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: PixelChecksum Coordinates.

16 Sep 2021, 07:05

I don't know why that area selector isn't working for you, but perhaps this will serve you better.

See the Numpad1 hotkey for useage. i.e You just use this if(Positions := TargetArea.Set())

Code: Select all

#SingleInstance, Force
SetBatchLines, -1
return

Numpad1::
	if(Positions := TargetArea.Set())
		msgbox,% "X1: " Positions.X1 "`nY1: " Positions.Y1 "`nX2: " Positions.X2 "`nY2: " Positions.Y2 "`nW: " Positions.W "`nH: " Positions.H
	else
		msgbox, Operation Canceled
	return

*ESC::ExitApp


;***********************************************************************************************************************************************
;***********************************************************************************************************************************************
;TargetArea Class By: Hellbent
; Jan 7th, 2021
; Select and show a rectangular zone on your screen (returns a object with X1, X2, Y1, Y2, W, H Keys)
; Credits: 
;***********************************************************************************************************************************************
;***********************************************************************************************************************************************
class TargetArea	{
	Set(color:="00FF00"){
		This.Color := color
		This.MonitorBounds := []
		This._CreateWindows()
		return This._SetPositions()
	}_CreateWindows(){
		local Hwnd, bd, tx, ty, Cmon
		CoordMode, Mouse, Screen
		MouseGetPos, tx, ty
		This.Name := [], This.Cross := []
		Gui, HBBackgroundGuiHB:New,  +AlwaysOnTop -Caption -DPIScale +ToolWindow +LastFound
		Gui, HBBackgroundGuiHB:Color,% This.Color
		WinSet, Transparent, 100
		Loop, % This._GetMonitorCount()	{
			This.Name[A_Index] := "HBSearchAreaWindowHB_" A_Index
			This.Cross[A_Index] := {}
			This.MonitorBounds[A_Index] := This._GetMonitorBounds(A_Index)
			Gui, % This.Name[A_Index] ":New", +AlwaysOnTop -Caption -DPIScale +ToolWindow +LastFound 
			WinSet, TransColor, 123456
			Gui, % This.Name[A_Index] ":Color", 123456
			Gui, % This.Name[A_Index] ":Margin", 0, 0
			Gui, % This.Name[A_Index] ":Add", Progress, % "x0 y" ty-This.MonitorBounds[A_Index].Y1  " w" This.MonitorBounds[A_Index].X2 - This.MonitorBounds[A_Index].X1 " h1 hwndhwnd BackgroundBlack cBlack Disabled", 100
			This.Cross[A_Index].Horz1 := hwnd
			Gui, % This.Name[A_Index] ":Add", Progress, x0 y0 w0 h0 hwndhwnd BackgroundBlack cBlack Disabled, 100
			This.Cross[A_Index].Horz2 := hwnd
			Gui, % This.Name[A_Index] ":Add", Progress, % "x" tx - This.MonitorBounds[A_Index].X1 " y0 w1 h" This.MonitorBounds[A_Index].Y2 - This.MonitorBounds[A_Index].Y1 " hwndhwnd BackgroundBlack cBlack Disabled", 100
			This.Cross[A_Index].Vert1 := hwnd
			Gui, % This.Name[A_Index] ":Add", Progress, x0 y0 w0 h0 hwndhwnd BackgroundBlack cBlack Disabled, 100
			This.Cross[A_Index].Vert2 := hwnd
			Gui, % This.Name[A_Index] ":Show", % "x" This.MonitorBounds[A_Index].X1 " y" This.MonitorBounds[A_Index].Y1 " w" This.MonitorBounds[A_Index].X2 - This.MonitorBounds[A_Index].X1 " h" This.MonitorBounds[A_Index].Y2 - This.MonitorBounds[A_Index].Y1
		}
	}_SetPositions(){
		local tx, ty, Positions := {}, sx, sy, lx, ly, cancel
		CoordMode, Mouse, Screen
		While(!GetKeyState("ctrl")){
			if(GetKeyState("Alt")){
				Cancel := True
				break
			}
			MouseGetPos, tx, ty
			if(tx!=lx||ty!=ly){
				lx := tx, ly := ty
				ToolTip, Press "ctrl" to set the first position `nX: %tx% Y: %ty% `nPress "Alt" to cancel
				Loop, % This._GetMonitorCount()	{
					GuiControl, % This.Name[A_Index] ":Move", % This.Cross[A_Index].Horz1, % "x0 y" ty-This.MonitorBounds[A_Index].Y1  " w" This.MonitorBounds[A_Index].X2 - This.MonitorBounds[A_Index].X1 " h1"
					GuiControl, % This.Name[A_Index] ":Move", % This.Cross[A_Index].Vert1,  % "x" tx - This.MonitorBounds[A_Index].X1 " y0 w1 h" This.MonitorBounds[A_Index].Y2 - This.MonitorBounds[A_Index].Y1
				}
			}
			Sleep, 30
		}
		Positions.X1 := tx, Positions.Y1 := ty, lx := "", ly := ""
		ToolTip,
		While(GetKeyState("ctrl")){
			if(Cancel||GetKeyState("Alt")){
				Cancel := True
				break
			}
			Sleep, 30
		}
		While(!GetKeyState("ctrl")){
			if(Cancel||GetKeyState("Alt")){
				Cancel := True
				break
			}
			MouseGetPos, tx, ty
			if(tx!=lx||ty!=ly){
				lx := tx, ly := ty
				ToolTip, Press "ctrl" to set the second position `nX: %tx% Y: %ty% `nPress "Alt" to cancel
				(tx<Positions.X1)?(sx:=tx):(sx:=Positions.X1)
				(ty<Positions.Y1)?(sy:=ty):(sy:=Positions.Y1)
				Gui, HBBackgroundGuiHB:Show, % "x" sx " y" sy " w" ABS(tx-Positions.X1) " h" ABS(ty-Positions.Y1) " NA"
				Loop, % This._GetMonitorCount()	{
					GuiControl, % This.Name[A_Index] ":MoveDraw", % This.Cross[A_Index].Horz2, % "x0 y" ty-This.MonitorBounds[A_Index].Y1  " w" This.MonitorBounds[A_Index].X2 - This.MonitorBounds[A_Index].X1 " h1"
					GuiControl, % This.Name[A_Index] ":MoveDraw", % This.Cross[A_Index].Vert2,  % "x" tx - This.MonitorBounds[A_Index].X1 " y0 w1 h" This.MonitorBounds[A_Index].Y2 - This.MonitorBounds[A_Index].Y1
				}
			}
			Sleep, 30
		}
		Positions.X2 := tx, Positions.Y2 := ty, Positions.W := ABS(Positions.X2-Positions.X1), Positions.H := ABS(Positions.Y2-Positions.Y1)
		ToolTip,
		This._DestroyWindows()	
		return (Cancel)?(0):(Positions)
	}_GetMonitorCount(){
		local MonitorCount
		SysGet, MonitorCount, MonitorCount
		return MonitorCount
	}_GetMonitorBounds(Index){
		local Mon, MonLeft, MonTop, MonRight, MonBottom, MonObj := {}
		SysGet, Mon, Monitor , % Index
		MonObj.X1 := MonLeft, MonObj.Y1 := MonTop, MonObj.X2 := MonRight, MonObj.Y2 := MonBottom
		return MonObj
	}_DestroyWindows(){
		Gui, HBBackgroundGuiHB:Destroy
		Loop, % This._GetMonitorCount()
			Gui, % This.Name[A_Index] ":Destroy"
	}
}


Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: PixelChecksum Coordinates.

16 Sep 2021, 07:12

Display the numeric content of these 4 variables in a Msgbox and then call ScrCmp() with these 4 numbers.
Means you should change the script accordingly so that a msgbox displays these values!
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: PixelChecksum Coordinates.

16 Sep 2021, 07:18

Hellbent wrote:
16 Sep 2021, 07:05
I don't know why that area selector isn't working for you, ]
If by area selector you mean using windows and left click ,'

its working.

I am able to select the area which gets highlighted in red

I am facing a problem with the coordinates.
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: PixelChecksum Coordinates.

16 Sep 2021, 07:50

Rohwedder wrote:
16 Sep 2021, 07:12
Display the numeric content of these 4 variables in a Msgbox and then call ScrCmp() with these 4 numbers.
Means you should change the script accordingly so that a msgbox displays these values!
I really apologise for being so tiresome. Kindly bear with me for just a little while longer.

Based on what I understand, this is what the script does:

monitors an area for change and performs an action. ( the action can be changed by the user )

In this case that action is a message box. ( That is, when a screen change is detected, a message box is shown, as that's what the "action" is defined according to this script)

in addition to being the defined "action", this message box also serves as an information source of the x / y coordinates selected using the windows key and left click.


Usually the x y coordinates of a rectangle or a square are entered as follows.

the x coordinate is the bottom left "x" value
the y coordinate is the top right "Y" value

The width of a rectangle or a square are calculated as follows

w = the difference between bottom left x value and top right x value

h = the difference between bottom left y value and top right y value.


Now, am I correct in understanding that the message box showing the x y coordinates is showing the bottom left "X" value and the top right "Y" value ?

If so , how do I get the Bottom Left "Y" value and the top right "X" value ? (for obtaining the w and h)


assuming that I somehow get it,

is this how the whole looks like ?


ScrCmp(vX1, vY1, vW, vH) =
ScrCmp(vX10, vY20, vW, vH)




and I didn't understand this at all
Display the numeric content of these 4 variables in a Msgbox and then call ScrCmp() with these 4 numbers.
do you mean I should create a message box that on running shows the x,y,w,h values, and then call the function ScrCmp()

where ScrCmp() function = ScrCmp(vX10, vY20, vW, vH) ?
User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: PixelChecksum Coordinates.

16 Sep 2021, 10:05

He’s simply saying that in the line prior to calling ScrCmp(), add a MsgBox command that displays the values of the four parameters you are passing, such as this:

Code: Select all

MsgBox, % "vX1 = " vX1 "`nvY1 = " vY1 "`nvW = " vW "`nvH = " vH
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: PixelChecksum Coordinates.

16 Sep 2021, 19:32

Oh I see !

So I should get the coordinates by myself. The script won't provide them.

That was my doubt.
User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: PixelChecksum Coordinates.

16 Sep 2021, 19:55

Fulminare wrote: So I should get the coordinates by myself. The script won't provide them.
Not sure what you mean by this. The MsgBox line I showed is just meant to show the values contained in those variables. It’s not getting them from anywhere except what’s already in them. It’s meant to show what you’re about to pass as parameters to that function for troubleshooting purposes. It otherwise doesn’t add any value to the script, and it should be removed once you are finished troubleshooting.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], RussF, Spawnova and 130 guests