Always On Top in Windows 10 using AutoHotkey

Mexican Morning Show – ‘Dia y Dia’

Updated: 14-May-2017
I’ve replaced the original script with a fantastic script that combines transparency, click-through, along with always on top.

One way I’ve attempted to advance my understanding of the Spanish language has been to watch or listen to local Spanish television using the Media Center called Kodi with the Adryan’s List addon.  In some future post, I’ll detail how to set all this up, but basically I can watch hundreds of live television channels from all around the globe.

So now that I’ve been watching TV and Movies — I’d like to keep the window displaying Kodi open and top of my desktop while I’m working or using the laptop.

 

The AutoHotkey website

Using Google I found a program called AutoHotkey.

Current version is 1.25
Testing / Alpha release: 2.0

I decided to use 1.25 since it was the stable release and most of the information on the web was related to version 1.

At first I had attempted to run the Alpha 2.0 release.  It started with a message saying script not found.  I later realized this was user error and that AutoHotkey expects to be initiated by a script, not run directly.  So, in short, my user error.

I kicked off AutoHotkey 1.25 and was presented with a help file.  AutoHotkey works by executing scripts, the program itself has no interface and launching the program directly displays the help file which explains the command and function options as well as scripting syntax.

I created a text file called always_on_top.ahk — the AHK extension is the extension used by AutoHotkey.

Update May 14th:  Previously, I had been crafting my own script, but then I ran across a new script on the Hotkey Forums ( https://autohotkey.com/board/topic/53249-transparent-andor-always-on-top/ ) that allows for transparency (ALT+scroll up or scroll down with the mouse wheel) and click-through (ALT+Z | ALT+X) in addition to the Always on Top functionality (ALT+A).

Source code of always_on_top.ahk file:

#InstallKeybdHook
#SingleInstance force
/*
collected from: https://autohotkey.com/board/topic/53249-transparent-andor-always-on-top/page-2

Hotkeys:
Alt-A: make window always on top

Alt-wheelup: make window less transparent
Alt-wheeldown: make window more transparent

Alt-X: make window clickthoughable
Alt-Z: make window under mouse unclickthroughable
*/
winArr := Object()
OnExit, Exit

!a::
WinGet, currentWindow, ID, A
addToWinArr(currentWindow)
WinGet, ExStyle, ExStyle, ahk_id %currentWindow%
if (ExStyle & 0x8) ; 0x8 is WS_EX_TOPMOST.
{
 Winset, AlwaysOnTop, off, ahk_id %currentWindow%
 SplashImage,, x0 y0 b fs12, OFF always on top.
 Sleep, 1500
 SplashImage, Off
}
else
{
 WinSet, AlwaysOnTop, on, ahk_id %currentWindow%
 SplashImage,,x0 y0 b fs12, ON always on top.
 Sleep, 1500
 SplashImage, Off
}
return

!wheelup::
WinGet, currentWindow, ID, A
addToWinArr(currentWindow)
if not (%currentWindow%)
{
 %currentWindow% := 255
}
if (%currentWindow% != 255)
{
 %currentWindow% += 5
 WinSet, Transparent, % %currentWindow%, ahk_id %currentWindow%
}
SplashImage,,w100 x0 y0 b fs12, % %currentWindow%
SetTimer, TurnOffSI, 1000, On
Return

!wheeldown::
SplashImage, Off
WinGet, currentWindow, ID, A
addToWinArr(currentWindow)
if not (%currentWindow%)
{
 %currentWindow% := 255
}
if (%currentWindow% != 5)
{
 %currentWindow% -= 5
 WinSet, Transparent, % %currentWindow%, ahk_id %currentWindow%
}
SplashImage,, w100 x0 y0 b fs12, % %currentWindow%
SetTimer, TurnOffSI, 1000, On
Return

!x::
WinGet, currentWindow, ID, A
addToWinArr(currentWindow)
WinSet, ExStyle, +0x80020, ahk_id %currentWindow%
return

!z::
MouseGetPos,,, MouseWin ; Gets the unique ID of the window under the mouse
addToWinArr(MouseWin)
WinSet, ExStyle, -0x80020, ahk_id %currentWindow%
Return

TurnOffSI:
SplashImage, off
SetTimer, TurnOffSI, 1000, Off
Return

addToWinArr(chwnd){
 global winArr
 if (!winArr.hasKey(chwnd))
 winArr[chwnd] := true
}

Exit:
 for currentWindow, b in winArr
 {
 WinSet, ExStyle, -0x80020, ahk_id %currentWindow%
 WinSet, Trans, 255, ahk_id %currentWindow%
 Winset, AlwaysOnTop, off, ahk_id %currentWindow%
 }
 ExitApp
return

When I changed the extension to ahk, the icon for the file changed to the AutoHotkey icon and I was provided with different context (right click) menu extensions to edit or compile the script.

To execute the script, right click on the file always_on_top.ahk and select Run Script. You’ll know AutoHotkey is running when you see the icon on your system tray.

It took me longer to write this article than it did to complete the process described within.

Day 341: Sharing this Road

So long time, no update.
Sometimes plans become quite circuitous and silence is not a void, but a time of transition.
[blah blah blah metaphysical stuff goes here]

I’ve moved my bicycle adventures over to www.sharethisroad.com

The new location is a joint venture with my partner, Esme, as we join forces to continue to bike SOUTH to Patagonia …

We’re leaving October 7th, 2016 from Sabula, Iowa and our first milestone on the road will be reaching St. Louis in a week or so.

So, jump on over to Share This Road and follow the adventures. We’ve also got a facebook page up here: www.facebook.com/sharethisroad