Outlines a rectangular region of the screen with a colored, click-through border.
This class is exported by the KS module.
HighlightObj := Highlight(X, Y, Width, Height, Color, Thickness)
Type: Integer
The top-left corner of the rectangle to outline, in screen coordinates. If omitted, 0 is used.
Type: Integer
The width and height of the rectangle, in pixels. If omitted, 0 is used, in which case nothing is shown until a size is set.
Type: String or Integer
The border color, as a color name such as "Lime", a hexadecimal string such as "FF0000", or a 0xRRGGBB integer. If omitted, red is used. Any other string raises a ValueError.
Type: Integer
The border thickness in pixels. If omitted, 2 is used. Zero hides the border.
Type: Highlight
Returns a new Highlight object. Constructing one does not display anything; call Show to put it on screen.
The border is drawn just outside the given rectangle, so the rectangle itself remains fully visible. The outline is always on top, never takes focus, and lets mouse input pass through to the windows beneath it.
The overlay is also destroyed when the Highlight object is garbage-collected, so keep a reference to it for as long as the outline should remain visible.
On high-DPI displays the thickness is scaled to the display containing the rectangle, so a 2-pixel border looks the same on every monitor.
All properties can be changed while the outline is displayed; the change takes effect immediately.
HighlightObj.X: The left edge of the rectangle, in screen pixels.
HighlightObj.Y: The top edge of the rectangle, in screen pixels.
HighlightObj.Width: The width of the rectangle, in pixels.
HighlightObj.Height: The height of the rectangle, in pixels.
HighlightObj.Color: The border color. It can be set with a color name, a hexadecimal string or a 0xRRGGBB integer, and always reads back as a six-digit hexadecimal string such as "FF0000". Assigning any other string raises a ValueError and keeps the previous color.
HighlightObj.Thickness: The border thickness in pixels. Zero hides the border.
HighlightObj.IsVisible: Returns 1 if the outline is currently on screen and 0 otherwise. This property is read-only; use Show and Hide to change it.
HighlightObj.Hwnd: The window handle of the overlay, or 0 where the platform draws the overlay without a client-side window. This property is read-only. Hide and Show leave it unchanged, except for a Wayland layer-shell surface.
HighlightObj.Show(X, Y, Width, Height): Displays the outline, creating the overlay on first use, and returns immediately without blocking. Any coordinates given replace the current ones first, so Show doubles as a move or resize.
HighlightObj.Move(X, Y, Width, Height): Changes the rectangle without changing visibility. All parameters are optional, so Move(, , 300, 200) resizes without moving. On a hidden outline this only records the new geometry, to be used by the next Show.
HighlightObj.Hide(): Removes the outline from the screen but keeps the overlay for reuse. On Windows, Linux/X11 and macOS, the runtime retains its window; Wayland layer-shell surfaces and compositor overlays are created again by the next Show.
HighlightObj.Destroy(): Destroys the overlay and frees its resources. It is safe to call more than once, and the object can be reused afterwards: a later Show builds a new overlay.
Outlines a region for two seconds.
#Import "Ks" { Highlight }
Hl := Highlight(100, 100, 300, 200)
Hl.Show()
Sleep 2000
Hl.Destroy()
Follows the active window until Escape is pressed. Because the overlay is reused, the outline tracks the window without flicker.
#Import "Ks" { Highlight }
Hl := Highlight(0, 0, 0, 0, "Lime", 3)
Hl.Show()
SetTimer Track, 100
Track()
{
if WinExist("A")
{
WinGetPos &X, &Y, &W, &H, "A"
Hl.Move(X, Y, W, H)
}
}
Esc::ExitApp