0
votes

I want a functionality like when you press 'Win' and 'd' where you see the desktop and if you press it again it restores all windows.

How would one implement that in AHK but with only the active window?

Thanks

UPDATE:

Following code was added, but still unable to restore the minimized window when pressing ALT+s again.

!s::
WinGet, active_id, ID, A
if (toggle:=!toggle)
    WinMinimize, ahk_id %active_id%
else
    WinRestore, ahk_id %active_id%
Return
1

1 Answers

1
votes

The Win+Down shortcut does this, but the functionality somewhat varies depending on what particular window is active. Given a maximized Window, usually using the Win+Down shortcut down twice normally does what you want.

So, replacing the Win+D shortcut w/ 2x Win+Down looks like this:

#d::
Send #{down}
Send #{down}
return

Alternatively, using ahk's built in WinMinimize function (Which will probably work better):

#d::WinMinimize, A

Update: Added the requested restore functionality

Toggle:=0

#d::
Toggle^=1
if(Toggle){
    WinGetTitle, name, A
    WinMinimize, %name%
}
else
    WinRestore, %name%
return

Update 2: More reliable hwnd-based version courtesy of 0x464e

#d::
    if (toggle:=!toggle)
        WinMinimize, % "ahk_id " _hwnd := WinExist("A")
    else
        WinRestore, % "ahk_id " _hwnd
return