How to set window to always on top using AutoHotKey v2?

I need to write a script to make the active window always on top, but all the examples are for AutoHotKey v1. How can I do this with AHK v2?

0

2 Answers

Use this (Hotkey is CTRL + SPACE):

^space::
{ WinSetAlwaysOnTop -1, "A"
}

How it works:

This script uses the WinSetAlwaysOnTop method to accomplish its goal. It takes several parameters, but not all of them are mandatory. -1 tells the function to toggle the setting to the opposite of whatever it was (e.g. OFF --> ON), and "A" tells it to use the currently active window (whichever window has focus). You can also pass it the name of a specific window, like "Calculator".

Here are some links to the relevant documentation:

0

Modified some AHK v1 code to alter the window title when a window's "OnTop" status is changed

!t:: { ; ALT + t
Title_When_On_Top := "! " ; change title "! " as required
t := WinGetTitle("A")
ExStyle := WinGetExStyle(t)
if (ExStyle & 0x8) { ; 0x8 is WS_EX_TOPMOST WinSetAlwaysOnTop 0, t ; Turn OFF and remove Title_When_On_Top WinSetTitle (RegexReplace(t, Title_When_On_Top)), "A"
} else { WinSetAlwaysOnTop 1, t ; Turn ON and add Title_When_On_Top WinSetTitle Title_When_On_Top . t, t }
}

Original code is thanks to Linear Spoon

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like