AlwaysOnTop not staying on top

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
UncleDaddySwiss
Posts: 4
Joined: 13 Dec 2017, 23:17

AlwaysOnTop not staying on top

13 Dec 2017, 23:55

Hey, just started using Autohotkey recently and I have a script which includes a key combo to make the active window "AlwaysOnTop," however, it works only until a different window is clicked, and then the original is clicked again. Then the AlwaysOnTop is disabled. The code is

Code: Select all

#t::
     WinSet, AlwaysOnTop, Toggle, A
Return
Any help is appreciated.
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: AlwaysOnTop not staying on top

14 Dec 2017, 10:14

Use this instead: #t::WinSet, AlwaysOnTop,, A

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

UncleDaddySwiss
Posts: 4
Joined: 13 Dec 2017, 23:17

Re: AlwaysOnTop not staying on top

14 Dec 2017, 11:07

Thanks for the reply, but the same outcome. I click on the top window to make it active, set it to alwaysontop using the script, click on a window under it, top window stays on top, but then I click on top window and then when I click on the window under it again it becomes the top window and the "top" window gets sent back. (I hope that makes sense)
Thank you for trying though.
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: AlwaysOnTop not staying on top

14 Dec 2017, 11:50

Some windows don't keep the AlwaysOnTop attribute persistently. Perhaps the software controlling that window sets the attributes back or something. You could make a script that will change the attribute to AlwaysOnTop every so often (100 ms, perhaps) once you've identified the window with the hotkey and ascertained its unique ID (HWND).
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: AlwaysOnTop not staying on top

14 Dec 2017, 12:00

This may solve the problem. The issue is: what happens when two windows have the WS_EX_TOPMOST extended window style. If you alternate between two on-top windows with alt-tab, the active one will overlap the inactive one. Thus it may be desirable, when you make one window on-top, to make the other window not on-top.
- Btw you may get weird results if you try to make certain windows on-top, so you may want to add an exclude list based on the window class. There is some example code for that commented out below.

Code: Select all

q:: ;set current window to always-on-top (set any previous window to not always-on-top)
WinGet, hWnd, ID, A
;WinGetClass, vWinClass, % "ahk_id " hWnd
;if (vWinClass = "Shell_TrayWnd")
;	return
if (hWndOnTopLast = hWnd)
	return
else if hWndOnTopLast
	WinSet, AlwaysOnTop, Off, % "ahk_id " hWndOnTopLast
hWndOnTopLast := hWnd
WinSet, AlwaysOnTop, On, % "ahk_id " hWnd
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
UncleDaddySwiss
Posts: 4
Joined: 13 Dec 2017, 23:17

Re: AlwaysOnTop not staying on top

14 Dec 2017, 12:08

Thanks for the replies. So far I've only tested with Notepad++ being the "under" window and Microsoft Edge being the window I'm trying to keep on top. I'm just starting to learn this language, so I will look into the suggestions.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: AlwaysOnTop not staying on top

14 Dec 2017, 12:13

Windows 10, with built-in MS software, typically causes unusual problems for AutoHotkey (although there may be workarounds). Also, admin windows can cause problems. So I would recommend using some simple non-Microsoft, non-admin software for doing testing e.g. NirSoft utilities, they are portable, and usually (always?) under a megabyte in size (note: one or two NirSoft utilities do need to be run in admin mode).
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
UncleDaddySwiss
Posts: 4
Joined: 13 Dec 2017, 23:17

Re: AlwaysOnTop not staying on top

14 Dec 2017, 12:31

Yep, you are correct. I know I should have done this before, but I have tried other windows which do work as expected. Thanks for all the replies!

Edit: Ok, strange, it seems that its the specific combination of Edge and Notepad++. Every other combination with those two apps and other programs works fine.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 299 guests