cover window region

Post your working scripts, libraries and tools
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

cover window region

31 Jul 2017, 08:48

This script checks the window criteria (title/class etc) and size/position of the active window. If a match is found, then a rectangle of a specified colour is placed at a certain point.

I use this occasionally for videos on Media Player Classic, that have a timer that is constantly updating. E.g. I like it so that it blocks the timer when it is fullscreen or maximised or when I have Notepad at the bottom of the screen for making notes, and the video at the top.

Another use for the script is to place a coloured square on a window to help distinguish between different windows.

I also provided a script for appending the screen and cursor coordinates, and the colour under the cursor to the clipboard, to help with getting the information needed to add more items to the list.

If anyone has posted anything similar do post a link below. Thanks.

Code: Select all

;cover window region by jeeswg
#SingleInstance force

;window criteria|XYWH window|XYBR cover region|RGB 6-character hex cover colour|(coordinates relative to) Screen/Window or use first letter
oArray := {}
oArray.Push(["ahk_class MediaPlayerClassicW","-8 -8 1296 696","157 56 239 87","ABCDEF","S"])
oArray.Push(["ahk_class MediaPlayerClassicW","0 0 1280 720","19 17 121 60","ABCDEF","S"])
oArray.Push(["ahk_class Notepad","","0 0 30 30","FF0000","W"])
;oArray.Push(["A","","0 0 30 30","FFFF00","W"])
oArray.Push(["A","","0 0 30 30","FFFF00","S"])

Loop, % oArray.Length()
{
	oTemp := StrSplit(oArray[A_Index,3], " ")
	oArray[A_Index,3] := "x" oTemp.1 " y" oTemp.2 " w" (oTemp.3-oTemp.1) " h" (oTemp.4-oTemp.2)
}
oTemp := ""

Loop
{
	WinGet, hWnd1, ID, A
	WinGetPos, vWinX1, vWinY1, vWinW1, vWinH1, % "ahk_id " hWnd1
	vCoords1 := vWinX1 " " vWinY1 " " vWinW1 " " vWinH1
	if (hWnd1 = hWnd2) && (vCoords1 = vCoords2)
	{
		hWnd2 := hWnd1, vCoords2 := vCoords1
		continue
	}
	vIsMatch := 0
	Loop, % oArray.Length()
		if (hWnd1 = WinExist(oArray[A_Index,1]))
		&& ((vCoords1 = oArray[A_Index,2]) || ("" = oArray[A_Index,2]))
		{
			if (SubStr(oArray[A_Index,5], 1, 1) = "S")
				Progress, % "b zh0 cw" oArray[A_Index,4] " " oArray[A_Index,3]
			else
			{
				oTemp := StrSplit(RegExReplace(oArray[A_Index,3], "[a-z]"), " ")
				Progress, % "b zh0 cw" oArray[A_Index,4] " x" (vWinX1+oTemp.1) " y" (vWinY1+oTemp.2) " w" oTemp.3 " h" oTemp.4
				oTemp := ""
			}
			vIsMatch := vIsShown := 1
			break
		}
	if !vIsMatch && vIsShown
	{
		Progress, Off
		vIsShown := 0
	}
	hWnd2 := hWnd1, vCoords2 := vCoords1
	Sleep, % vInterval
}

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

;q:: ;append to clipboard: screen and cursor coordinates, and colour under cursor (RGB)
WinGetPos, vWinX, vWinY, vWinW, vWinH, A
vCoords := vWinX " " vWinY " " vWinW " " vWinH
CoordMode, Mouse, Screen
MouseGetPos, vCurX, vCurY
CoordMode, Pixel, Screen
PixelGetColor, vColRGB, % vCurX, % vCurY, RGB
Clipboard .= "`r`n`r`n" vCoords "`r`n" vCurX " " vCurY "`r`n" vColRGB
return

;==================================================
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4440
Joined: 17 Jul 2016, 01:02
Contact:

Re: cover window region

02 Aug 2017, 09:04

Hello jeeswg. I tried this the other day. It works fine. I like to block some youtube timers to avoid spoilers, I might use this for such purposes. Thanks for sharing. :wave:
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: cover window region

11 May 2019, 19:02

Here is a simple example to cover a window region. There is some more complicated code in the OP above.

Code: Select all

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

;cover a window region (simple example)

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

#NoEnv
AutoTrim, Off
SetBatchLines, -1

#SingleInstance force
#KeyHistory 0
#UseHook
#Warn
ListLines, Off
Menu, Tray, Click, 1
Menu, Tray, Tip, % RegExReplace(A_ScriptName, "\.[^.]*$")

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

;options:

;vWinTitle := "ahk_class Notepad"
vWinTitle := "Untitled - Notepad"

vColRGB := "ABCDEF"

;cover region X/Y/W/H relative to window W/H
;oCov := [10, 10, 10, 10], oWin := [40, 40]
;oCov := [10, 10, 10, 10], oWin := [30, 30]
;oCov := [10, 10, 20, 20], oWin := [30, 30]
;oCov := [0, 0, 30, 30], oWin := [30, 30]
;oCov := [10, 10, 30, 30], oWin := [40, 40]
;oCov := [0, 0, 20, 20], oWin := [40, 40]
oCov := [20, 20, 20, 20], oWin := [40, 40]

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

WinGet, hWndTarget, ID, % vWinTitle
vWinPos2 := "", hWnd2 := 0
if !hWndTarget
{
	MsgBox, % "error: window not found"
	return
}
for _, vValue in StrSplit("XYWH")
	vCov%vValue%1 := oCov[A_Index]
vWinW1 := oWin.1, vWinH1 := oWin.2

Loop
{
	WinGet, hWnd, ID, A
	if !(hWnd = hWnd2)
	&& (hWnd2 = hWndTarget)
		Progress, Off
	else if (hWnd = hWndTarget)
	{
		WinGetPos, vWinX2, vWinY2, vWinW2, vWinH2, % "ahk_id " hWndTarget
		vWinPos := Format("x{} y{} w{} h{}", vWinX2, vWinY2, vWinW2, vWinH2)
		if !(vWinPos = vWinPos2) || !(hWnd2 = hWndTarget)
		{
			vCovX2 := vWinX2 + Floor(vCovX1 * (vWinW2/vWinW1))
			vCovY2 := vWinY2 + Floor(vCovY1 * (vWinH2/vWinH1))
			vCovW2 := Ceil(vCovW1 * (vWinW2/vWinW1))
			vCovH2 := Ceil(vCovH1 * (vWinH2/vWinH1))
			Progress, % "b zh0 cw" vColRGB " " Format("x{} y{} w{} h{}", vCovX2, vCovY2, vCovW2, vCovH2)
		}
		vWinPos2 := vWinPos
	}
	hWnd2 := hWnd
	Sleep, 100
}

;==================================================
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
elModo7
Posts: 167
Joined: 01 Sep 2017, 02:38
GitHub: elModo7
Location: Spain
Contact:

Re: cover window region

13 May 2019, 02:36

Thanks for sharing!
Might be useful to cover sensitive data when livestreaming, at least to cover it up a bit.
:beer:

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 32 guests