WinSet, TransColor Command for Onscreen Data (Intermediate AutoHotkey Tip)

The WinSet, TransColor Option Offers an Alternative Method for Placing Data and/or Images Onscreen and On Top without Interfering with Your Work

ComputorEdge AutoHotkey E-BooksLast time, we discussed the confusion caused by the words transparent and invisible. Sometimes they may mean visually transparent while other times transparent means mouse-click invisible (mouse clicks drop through to the page underneath). The WinSet, TransColor command means both when applied to a specific color within a window. This option is useful for removing everything on the screen except for text or an image.

The example in the online AutoHotkey documentation for the GUI Command “On-screen display (OSD) via transparent window” offers a good start:

CustomColor = EEAA99  ; Can be any RGB color.
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow 
Gui, Color, %CustomColor%
Gui, Font, s32  ; Set a large font size (32-point).
Gui, Add, Text, vMyText cLime, 
WinSet, TransColor, %CustomColor% 150 ; Make color invisible
SetTimer, UpdateOSD, 200
Gosub, UpdateOSD  ; Run first update
Gui, Show, x0 y400 NoActivate  

  MouseGetPos, MouseX, MouseY
  GuiControl,, MyText, X%MouseX%, Y%MouseY%
TransColor Example
The onscreen display consist of an invisible GUI window (both to the eye and mouse-click) showing only the coordinates for the position of the mouse cursor in the active window. The green text is not mouse-click transparent.

This script display a GUI window at a fixed screen location (see image at right) showing the active window coordinates for the mouse cursor. With the title bar and border removed, the window background itself is invisible, while the text is merely translucent. The semi-transparent text continuously displays data—updating every two-tenths of a second via the subroutine UpdateOSD.

The WinSet, TransColor command turns a specific color invisible both visually and to mouse clicks. Any text or images using different colors within the window remain visible and clickable.

Only one color may be set transparent at a time. Reissuing the command with a new color cancels the old setting. This means that the best use for the option is most likely the window background color. After removing the title bar and border (Gui, -Caption), applying WinSet, TransColor to the background color leaves only the inner window content showing.

In the script above, the WinSet, TransColor command turns the background color (EEAA99) invisible in the GUI window displaying only the lime green text (inside the red box). While the text becomes translucent by adding a transparent parameter to the TransColor statement (WinSet, TransColor, %CustomColor% 150—which affects every other non-CustomColor), those visible pixels continue blocking mouse clicks.

This mouse-click opaque property presents a problem if you want the entire window to be mouse-click invisible. Clicking directly on the lime green text activates the window—even though you can’t see it. To fix this issue, add the mouse-click Window Style (WS_EX_TRANSPARENT—E0x20), discussed last time to the Gui, Options command:

Gui +LastFound +AlwaysOnTop -Caption +ToolWindow +E0x20

The color value of the TransColor parameter may be either the color name (Red) or its six digit Hex code (FF0000).

This WinSet, TransColor technique provides an alternative approach to Window Spy (right click AutoHotkey tray icon to activate) and my sample WindowProbe.ahk script for detecting AutoHotkey window data.

Next time, we take a quick look at WinSet, Region.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s