0
votes

I'm finding some inconsistencies with the AlwaysOnTop function in AutoHotKey. Take the following script for example:

#+a::
{
    WinSet , AlwaysOnTop , , A
    return
}

#+b::
{
    WinSet , AlwaysOnTop , Toggle
    return
}

The first option is based on a script I have been using for years that was cobbled together from other sources. That version works to toggle the AlwaysOnTop setting on whatever is the currently active window.

The second option is how the current documentation says it should be done. This does nothing when I try to trigger the AlwaysOnTop setting.

It's not just that the documentation is wrong (at least not completely), because that syntax seems to work for another script that I just wrote. In this new script, I always want it to only activate the AlwaysOnTop mode, never toggle, so I'm using WinSet , AlwaysOnTop , On and it's working fine.

Leaving the on/off/toggle value out doesn't work either (though it should default to toggle), and neither does using -1 (a new option in the latest version of AHK). It's not throwing any errors to run this, but if I play with the commas then it does say it encountered a syntax error.

Any ideas why the documented syntax doesn't work? Is it an actual glitch in AHK, or am I just misunderstanding its use in this case? I don't even know why my original version works, since I can't find that syntax documented anywhere.

1
Maybe because of the Matching Behaviour, if you don't specify the WinTitle Parameter.user3419297

1 Answers

2
votes

The docs don't say that it can't be done the 1st way. It says that if you do it the first way it defaults to toggle. And there's also a link about WinTitle at the top of WinSet, where it describes what A does (take the active window).

If what is misleading you is seeing WinTitle as optional, WinTitle is only optional if you want to work with the Last Found Window.

For example you could do this:

IfWinActive, %WinTitle%
    WinSet, AlwaysOnTop ; Toggles AlwaysOnTop for the previously checked window.