Force a Window Always-On-Top with WinSet (Beginning AutoHotkey Tip)

While Not an Everyday Trick, Making a Window Always-On-Top with the AutoHotkey WinSet Command Comes in Handy

Even though Windows computers offer the average user massive computational power, many people keep a cheap handheld calculator sitting next to their keyboard. Sometimes, it’s just easier to do a quick calculation on this small device, rather than loading another app, or, worse yet, a spreadsheet. I don’t have the numbers, but I’d bet that you could find a solar-powered calculator beside many Windows computers. (Or, maybe people use their smartphone calculator.)

It may seem crazy since all versions of Windows include an app for simple mathematics. Load the program (Run calc, microsoft_key+R, enter calc, then click OK) and the app pops open. However, Microsoft did not have the foresight to build in an always-on-top feature which would prevent the calculator from disappearing behind other windows.

AutoHotkey_Tricks_150

*          *          *

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.

*          *          *

Commonly, when using the calc app, people jump between the on-screen number cruncher and the target program where they enter the results (e.g. tax preparation software, calories consumed, etc). Unfortunately, every time they move to the target program, the calculator disappears behind the other window. Wouldn’t it be better if the calc app stayed on top—making movement between the two as simple as a click of the mouse?

Library Benefits

With the WinSet command, you can write an AutoHotkey script with only one line of code creating an ever-present Hotkey feature for turning on (and off again) always-on-top for any window:

^#F8::WinSet, AlwaysOnTop, toggle, A

Once this one-line script loads, if you want the computer’s calculator to stay on top, then, after selecting the open window, hit the Hotkey combination CTRL+WIN+F8 (^#F8). AutoHotkey uses the WinSet command to set the status of the active window (A) to AlwaysOnTop.

Note: This Always_on_Top.ahk script is available as a download. It may seem a little silly to offer a download which includes only one line of code, but the compiled EXE version (Always_on_Top.exe) can run on any Windows computer without previously loading the main AutoHotkey program.

Want to get rid of the calculator? Either close the window or execute the Hotkey combination again. Hitting CTRL+WIN+F8 toggles the AlwaysOnTop feature off again with the toggle option.

The beauty of this command is that it works for any Windows window—not only calculators. In fact, a project where I needed to copy (or drag) a number of filenames from one program window to another prompted me to highlight this technique.

I used my always-on-top Hotkey (part of my main AutoHotkey script) to set the active source window to this priority position. Moved and resized the window so it wouldn’t interfere, then proceeded to quickly drag the names from the on-top window to the target window. No searching for a disappearing source window. I don’t do this everyday, but when I do, it works great.

The simplicity of this technique makes me wonder why I didn’t include it in the free AutoHotkey Tricks e-book. (To be fair to myself, it does appear in A Beginner’s Guide to AutoHotkey.) Truthfully, I often use always-on-top in my applications—especially not-to-be-ignored reminders—at least, not until they have done their work. The GUI command includes an AlwaysOnTop setting:

Gui +AlwaysOnTop +Resize

I copied the above line of code from the CalorieCount.ahk script. As to when to use the Gui +AlwaysOnTop setting, that depends upon whether the app needs to be merely available or in your face (e.g. AutoHotkeyControl.ahk, DateMenus.ahk, and KeyPad.ahk—the cool onscreen keypad app).

Tip: Check the online documentation for any always-on-top behaviour of specific commands. Many commands either start out always-on-top (e.g. ToolTip, Progress/SplashImage, SplashTextOn) or include similar options. With the exception of the ToolTip pop-up, the WinSet command can turn off the always-on-top state of the generated windows.

The WinSet Command

As I reviewed WinSet, I realized that variations on the command might be worth exploring for additional applications. The WinSet command offers many more window manipulation features than merely setting windows to AlwaysOnTop. In addition to sending a window to the bottom, or bringing it to the top, WinSet includes a variety of options for changing the window shape (WinSet, Region), transparency (WinSet, Transparent), and making colors invisible—which includes clickthrough-ness (or allowing clicks to fall through to the  window underneath— WinSet, TransColor).

Next time, I plan to explore some of these other WinSet window manipulation techniques and possible practical applications.

 

One thought on “Force a Window Always-On-Top with WinSet (Beginning AutoHotkey Tip)

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Connecting to %s