Make a Window Transparent with the WinSet Command (Beginning AutoHotkey Tip)

When Setting a Window to Always-On-Top Make It See-through for Peeking Underneath

My last blog discussed a simple one-line script for forcing any Windows window always-on-top. The Hotkey works great and instantly toggles the feature on and off. However, at times when an window permanently sits over all other windows, it gets in the way of viewing the pages underneath. The AutoHotkey WinSet command allows us to change the transparency of that window so we can see right through it.


*          *          *

Get your free download of the e-book AutoHotkey Tricks You Ought to Do with Windows. The new Third Edition includes a number of useful AutoHotkey techniques, plus the Table of Contents and the Indexes from the other five e-books. Pick it up as an easy download in any of the three formats: EPUB, MOBI, and PDF.

*          *          *

This see-through technique comes in handy when setting the calculator app to always-on-top and we still want to check the numbers in the window below. Rather than moving and resizing the calculator, one simple Hotkey can make the active calculator window semi-transparent:

^#F9::WinSet, Transparent, 125, A
Transparent Calculator
By making the calculator transparent the window underneath shows through while the calculating continues to work.

The Hotkey combination CTRL+microsoft_key+F9 (^#F9) uses the WinSet command to set the opaqueness of the active window (A) to about half (125 in the range of 0 to 255). The window in back instantly shows through. In combination with the always-on-top feature from last time, any utility window such as an onscreen calculator becomes much less obtrusive.

Note: When removing the title bar from an AutoHotkey GUI window (Gui -Caption), the AlwaysOnTop and Transparent features of the WinSet command no longer works. These options must be set before removing the title bar. Otherwise, the technique functions with almost any Windows window.

Since WinSet, Transparent requires a specific numeric value, unlike the WinSet, AlwaysOnTop setting from last time, transparency does not toggle on and off. A number of approaches work for making the window opaque again, but by far creating another Hotkey for resetting the active window is the easiest:

^#F10::WinSet, Transparent, 255, A

In this case, the Hotkey combination CTRL+microsoft_key+F10 (^#F10) removes all transparency (255—the max opaqueness) from the active window (A).

With these two Hotkeys, any active window can be made semi-transparent (CTRL+microsoft_key+F9) or toggled back to its original state (CTRL+microsoft_key+F10). This works independently of all other open windows. This trick also works for the Taskbar by first clicking on an empty area in the bar, then activating the Hotkey combination.

Make Help Windows Easier to Use

When used in combination with always-on-top, this window transparency method also solves another recurring problem. Many times while working with particular programs or Web sites, I’ve needed to consult the Help system. Usually, a window pops up with the pertinent instructions. However, if they are step-by-step procedures, then the same problem of jumping back and forth between windows occurs. Now WinSet solves the problem.

First, I use the Hotkey from the last blog to set the window to always-on-top. Next, I set the to window semi-transparent (CTRL+microsoft_key+F9) allowing me to view both windows simultaneously. By doing this I have minimized the annoyance caused by jumping between the two apps. Finally, when done, I simply close the Help window.

Note: These two Hotkeys (and the selection menu snippet below) now appear in the Always-on-Top.ahk script found at the ComputorEdge AutoHotkey Scripts page for download.

Multiple Values for Transparency

Although not quite as simple as the above examples, the value for opaqueness can be made adjustable. You could setup a new Hotkey for each of your desired transparency levels, but that would produce a pretty cumbersome script.

One option would be a pop-up menu using the Menu command:

  Menu, Transparency, Add, 255, SetTrans
  Menu, Transparency, Add, 190, SetTrans
  Menu, Transparency, Add, 125, SetTrans
  Menu, Transparency, Add, 65, SetTrans
  Menu, Transparency, Show

SetTrans:     ; subroutine run by menu item
  Sleep 100   ; delay 100 milliseconds  
  WinSet, Transparent, %A_ThisMenuItem%, A

Tranparency Menu

This particular snippet of AutoHotkey code creates (Menu, Transparency, Add  …) and displays (Menu, Transparency, Show) the Menu named Transparency each time the Hotkey combination CTRL+microsoft_key+F11 (^#F11) routine activates. After making a menu selection, AutoHotkey inserts the menu item value into the WinSet, Transparent command (%A_ThisMenuItem%) in the SetTrans Label (subroutine) making the target adjustment to the active window’s opaqueness.

Tip: Depending on what other processes are running, occasionally the WinSet command may execute before the menu completely deactivates. If so, nothing happens. To protect against this random occurrence, add the Sleep 100 command which pauses the script for  100 milliseconds (1/10 of a second) and allows the menu to close completely.

Note: The snippet may be altered to create the menu only once by putting all the Menu, Transparent, Add, … commands in the auto-execute section at the beginning of the script. However, by keeping the code inside the Hotkey (and recreating the menu each time) the Hotkey remains modular, allowing the addition of the script to or including it in (#Include directive) other AutoHotkey scripts without splitting the snippet into two parts—one for the auto-execute section and one for the Hotkey.

You can find slicker, but more complex methods for changing window transparency. The old AutoHotkey forum offers a script which uses Hotkeys to decrease and increase the value of opaqueness on each activation.

ComputorEdge AutoHotkey E-BooksIf you want to get really fancy, then you might use the mouse wheel to set the transparency level. While I haven’t done it here, the techniques found in the blog “Windows Volume Control Using Your Mouse Wheel and the AutoHotkey #If Directive” might get you started—but, it’s definitely not a beginning level task.

As for me, I’m happy with the original two levels of transparency: opaque and semi-transparent.



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