Active Window Always On Top, Off Top if no more ative

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
pickone
Posts: 16
Joined: 30 Sep 2017, 10:02

Active Window Always On Top, Off Top if no more ative

30 Jan 2021, 12:26

Hi guys!

I hate because windows have no option to disable "stealing focus" if I load another application... Lets say, If i'm in Firefox and I run an application with a hotkey, I want that application run in the background, not stealing focus (Adobe apps are the worst into this)... I tried everything, registry, GPO, some ahk scripts... Nothing it is working...

For this, I am trying to make a script, which will make the active window OnTop and changes the title to "Active - Title...", If I change the focus to another application, old active (no more active) window should be renamed back as the original title and become not OnTop, but loop for new window active...and so on... This is what I have done till now, but it is not working... Any help?

Code: Select all

#Persistent   
SetTitleMatchMode, 1
SetTimer, action, 1000
Return

action:

WinGetTitle, ActiveTitle, A

If !winactive(OldWindow)
{
NewName_OldWindow := StrReplace(OldWindow, "Active - ")
WinSetTitle, %OldWindow%, , %NewName_OldWindow%
Winset, AlwaysOnTop, Off, %NewName_OldWindow%
}

if (winactive(ActiveTitle) & !winactive("Active -"))
{
OldWindow = %ActiveTitle%
WinSetTitle, %ActiveTitle%, , Active - %ActiveTitle%
Winset, AlwaysOnTop, On, %ActiveTitle%
}

Return
Last edited by pickone on 30 Jan 2021, 13:24, edited 1 time in total.
Pepineros
Posts: 45
Joined: 16 Apr 2018, 17:26
Location: Ireland

Re: Active Window Always On Top, Off Top if no more ative

30 Jan 2021, 13:01

Could you wrap your script in code tags for easier reading?

Can you say what isn't working right now?

- is the name of the active window updated with the "active -" prefix?
- if you change focus to a different window, are the names of both windows updated correctly?
- can a window lose focus while still being on top? I'm not sure how winset, alwaysontop works exactly.
pickone
Posts: 16
Joined: 30 Sep 2017, 10:02

Re: Active Window Always On Top, Off Top if no more ative

30 Jan 2021, 13:32

Nevermind, I manage to make the script work. Thanks!

Code: Select all

#Persistent   
SetTitleMatchMode, 1
SetTimer, action, 1000
Return

action:

WinGetTitle, ActiveTitle, A

If !winactive(OldWindow)
{
NewName_OldWindow := StrReplace(OldWindow, "Active - ")
Winset, AlwaysOnTop, Off, %NewName_OldWindow%
WinSetTitle, %OldWindow%, , %NewName_OldWindow%
}

if !winactive("Active -")
{
OldWindow = Active - %ActiveTitle%
Winset, AlwaysOnTop, On, %ActiveTitle%
WinSetTitle, %ActiveTitle%, , Active - %ActiveTitle%
}

Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], macromint, peter_ahk and 343 guests