autohotkeyalways-on-top

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?


Solution

  • 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: