Skip to content

Instantly share code, notes, and snippets.

@gustavomdsantos
Last active September 30, 2024 03:32
Show Gist options
  • Save gustavomdsantos/46f4b4615eeabb2089478cbcc83cda76 to your computer and use it in GitHub Desktop.
Save gustavomdsantos/46f4b4615eeabb2089478cbcc83cda76 to your computer and use it in GitHub Desktop.
AutoHotKey script that make any window Always-on-Top on Windows.
; Press Ctrl+Shift+Space to set any currently active window to be always on top.
; Press Ctrl+Shift+Space again set the window to no longer be always on top.
; Source: https://www.howtogeek.com/196958/the-3-best-ways-to-make-a-window-always-on-top-on-windows
^+SPACE::
WinGetTitle, activeWindow, A
if IsWindowAlwaysOnTop(activeWindow) {
notificationMessage := "The window """ . activeWindow . """ is now always on top."
notificationIcon := 16 + 1 ; No notification sound (16) + Info icon (1)
}
else {
notificationMessage := "The window """ . activeWindow . """ is no longer always on top."
notificationIcon := 16 + 2 ; No notification sound (16) + Warning icon (2)
}
Winset, Alwaysontop, , A
TrayTip, Always-on-top, %notificationMessage%, , %notificationIcon%
Sleep 3000 ; Let it display for 3 seconds.
HideTrayTip()
IsWindowAlwaysOnTop(windowTitle) {
WinGet, windowStyle, ExStyle, %windowTitle%
isWindowAlwaysOnTop := if (windowStyle & 0x8) ? false : true ; 0x8 is WS_EX_TOPMOST.
return isWindowAlwaysOnTop
}
HideTrayTip() {
TrayTip ; Attempt to hide it the normal way.
if SubStr(A_OSVersion,1,3) = "10." {
Menu Tray, NoIcon
Sleep 200 ; It may be necessary to adjust this sleep.
Menu Tray, Icon
}
}
Return
@diallobakary4
Copy link

diallobakary4 commented Nov 7, 2020

Is it possible to have a variant in which mouse hover on the "Always on" window makes it move to somewhere else?

@kg-maker
Copy link

This is very helpful, thank you! Works very well in Windows in general, but when using Citrix Workspace, it still runs on top of 'window of interest'. For example, I put Zoom as "always on top", but Citrix still hides it (while all other apps do not). Do you have any idea how to overcome it?

@todflak
Copy link

todflak commented Nov 16, 2020

Thanks for this, the TrayTip is a very nice addition from the simple way I had been using.

@zeroxia
Copy link

zeroxia commented Sep 20, 2022

Does not work for all windows, anybody know why?
e.g. with Dadroit JSON Viewer, this command does not work:

	Winset, Alwaysontop, , A

@AlexC1980
Copy link

TY

@Garry-ru
Copy link

Works just fine (Win 10), thanks, pal!

@gustavomdsantos
Copy link
Author

For users who encounter software that the script does not work, try running AutoHotKey as a Windows administrator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment