So that the search area is defined.
What does the message box do ?
The confusion started from this point
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 )
}
So I thought, the message box was just an action that gets triggered when screen change is detected, and it can be replaced with any other action of my choice.
Now in this script when screen change is detected,
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 )
}
A. a message box is shown (which is the "action" when screen change is detected)
B. It also contains x y info. (ref img 2)
Because the script I use for getting coordinates also shows it in a message box
Code: Select all
!c::
MouseGetPos, xpos, ypos
MsgBox, %xpos% %ypos%.
I thought the x y info shown in the msg box from img2 should be entered somewhere in the script