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
@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