AHK V2 script to hide/show the taskbar in Windows 11 Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
erbanku
Posts: 7
Joined: 07 Oct 2021, 23:04

AHK V2 script to hide/show the taskbar in Windows 11

Post by erbanku » 30 Jan 2023, 19:36

Can someone provide an updated Autohotkey V2 script to hide/show the taskbar in Windows 11?
My existing script with Autohotkey 1 is no longer working.
I searched the internet and was able to hide*(the taskbar disappeared only, but the taskbar space became empty and did not hide to free space--which is not what I wanted), but unable to enable it again.

Can anyone help?
Thank you in advance.

My old script works properly in V1:

Code: Select all

#!Z:: HideShowTaskbar(hide := !hide)
HideShowTaskbar(action) {
    static ABM_SETSTATE := 0xA, ABS_AUTOHIDE := 0x1, ABS_ALWAYSONTOP := 0x2
    VarSetCapacity(APPBARDATA, size := 2*A_PtrSize + 2*4 + 16 + A_PtrSize, 0)
    NumPut(size, APPBARDATA), NumPut(WinExist("ahk_class Shell_TrayWnd"), APPBARDATA, A_PtrSize)
    NumPut(action ? ABS_AUTOHIDE : ABS_ALWAYSONTOP, APPBARDATA, size - A_PtrSize)
    DllCall("Shell32\SHAppBarMessage", UInt, ABM_SETSTATE, Ptr, &APPBARDATA)
}

ntepa
Posts: 428
Joined: 19 Oct 2022, 20:52

Re: AHK V2 script to hide/show the taskbar in Windows 11  Topic is solved

Post by ntepa » 31 Jan 2023, 09:49

try this

Code: Select all

#!Z::HideShowTaskbar()

HideShowTaskbar() {
    static ABM_SETSTATE := 0xA, ABS_AUTOHIDE := 0x1, ABS_ALWAYSONTOP := 0x2
    static hide := 0
    hide := !hide
    APPBARDATA := Buffer(size := 2*A_PtrSize + 2*4 + 16 + A_PtrSize, 0)
    NumPut("UInt", size, APPBARDATA), NumPut("Ptr", WinExist("ahk_class Shell_TrayWnd"), APPBARDATA, A_PtrSize)
    NumPut("UInt", hide ? ABS_AUTOHIDE : ABS_ALWAYSONTOP, APPBARDATA, size - A_PtrSize)
    DllCall("Shell32\SHAppBarMessage", "UInt", ABM_SETSTATE, "Ptr", APPBARDATA)
}

erbanku
Posts: 7
Joined: 07 Oct 2021, 23:04

Re: AHK V2 script to hide/show the taskbar in Windows 11

Post by erbanku » 31 Jan 2023, 18:59

@ntepa
Works Now! Thanks a lot.

ninth6825
Posts: 1
Joined: 19 Jan 2024, 16:27

Re: AHK V2 script to hide/show the taskbar in Windows 11

Post by ninth6825 » 19 Jan 2024, 16:32

Thank you both for the help. I've been trying forever to modify this v2 code for my needs, but I'm coming up short. @ntepa, do you think you could help me out?

Basically, I'm trying to activate my "game" mode when I hit #g. When I hit that the first time, it will initiate the following AND hide the taskbar:

Code: Select all

#g::
{ 
Run("ms-settings:gaming-gamemode")
Sleep(125)
Send("#{Numpad1}")
Sleep(125)
Send("{Space}")
WinClose("Firefox")
WinClose("Calendar")
WinClose("Keep")
WinClose("Voice")
WinClose("Gmail")
WinClose("Signal")
Run("C:\Program Files\Pimax\PimaxClient\pimaxui\PimaxClient.exe")
}
I would like to add the hide taskbar to that. However, the next time I hit #g, all I want it to do is toggle game mode off and show the taskbar.

Can you assist me with this?

ntepa
Posts: 428
Joined: 19 Oct 2022, 20:52

Re: AHK V2 script to hide/show the taskbar in Windows 11

Post by ntepa » 19 Jan 2024, 17:41

@ninth6825 try this:

Code: Select all

#g::
{
    static hide := 0
    hide := !hide
    if !hide {
        Run("ms-settings:gaming-gamemode")
        Sleep(125)
        Send("#{Numpad1}")
        Sleep(125)
        Send("{Space}")
        WinClose("Firefox")
        WinClose("Calendar")
        WinClose("Keep")
        WinClose("Voice")
        WinClose("Gmail")
        WinClose("Signal")
        Run("C:\Program Files\Pimax\PimaxClient\pimaxui\PimaxClient.exe")
    } else {
        ; your code to toggle game mode off
    }
    HideShowTaskbar(hide)
}

HideShowTaskbar(hide) {
    static ABM_SETSTATE := 0xA, ABS_AUTOHIDE := 0x1, ABS_ALWAYSONTOP := 0x2
    APPBARDATA := Buffer(size := 2*A_PtrSize + 2*4 + 16 + A_PtrSize, 0)
    NumPut("UInt", size, APPBARDATA), NumPut("Ptr", WinExist("ahk_class Shell_TrayWnd"), APPBARDATA, A_PtrSize)
    NumPut("UInt", hide ? ABS_AUTOHIDE : ABS_ALWAYSONTOP, APPBARDATA, size - A_PtrSize)
    DllCall("Shell32\SHAppBarMessage", "UInt", ABM_SETSTATE, "Ptr", APPBARDATA)
}

Post Reply

Return to “Ask for Help (v2)”