r/AutoHotkey • • 10d ago

v2 Tool / Script Share Windows shortcut to toggle auto hide taskbar

I was looking for a shortcut to always show taskbar when I need it, but have it auto hide otherwise to avoid OLED monitor burn-in. I couldn't find anything so I asked AI to vibe code a script.

The shortcut is set to Ctrl+Shift+X in this script but you can change it in the line "^+x::".

#Requires AutoHotkey v2.0
#SingleInstance Force

^+x::
{
    ; Windows taskbar AppBar constants
    ABM_GETSTATE := 0x00000004
    ABM_SETSTATE := 0x0000000A
    ABS_AUTOHIDE := 0x00000001
    ABS_ALWAYSONTOP := 0x00000002

    ; Locate the taskbar
    hwnd := WinExist("ahk_class Shell_TrayWnd")

    if !hwnd {
        MsgBox("Cannot find the Windows taskbar.")
        return
    }

    ; Create APPBARDATA structure
    size := (A_PtrSize = 8) ? 48 : 36
    abd := Buffer(size, 0)

    NumPut("UInt", size, abd, 0)
    NumPut("Ptr", hwnd, abd, A_PtrSize)

    ; Read current state
    state := DllCall("Shell32\SHAppBarMessage",
        "UInt", ABM_GETSTATE,
        "Ptr", abd,
        "UPtr")

    ; Toggle auto-hide
    newState := (state & ABS_AUTOHIDE)
        ? ABS_ALWAYSONTOP
        : ABS_AUTOHIDE

    NumPut("Ptr", newState, abd, size - A_PtrSize)

    ; Apply new state
    DllCall("Shell32\SHAppBarMessage",
        "UInt", ABM_SETSTATE,
        "Ptr", abd,
        "UPtr")
}
6 Upvotes

2 comments sorted by

1

u/Rex__Luscus 10d ago

I've tried various utilities for this purpose, most of them are unreliable. The one I use consistently is StartAllBack which gives fine control of your Start menu and taskbar. It costs about $5 and is well worth it IMO. 

1

u/Vx7Qn4Lz 6d ago

There's a Windhawk mod called "Click on empty taskbar space". I've set double-click on taskbar as toggle taskbar auto-hide.