Page 1 of 1

Desktop (ahk_class Progman ahk_exe explorer.exe) not seen as active by AutoHotkey after icon hide

Posted: 25 Dec 2019, 04:40
by neogna2
If we in Win10 hide the Desktop icons and then click on the Desktop (the void where the Desktop icons were) then AutoHotkey sometimes does not detect ahk_class Progman ahk_exe explorer.exe as the active window. As a result hotkeys that use #IfWinActive ahk_class Progman do nothing after that click.

How to make such hotkeys work reliably after click on Desktop (the void where the Desktop icons were) even with Desktop icons hidden?

Is there different way to hide the Desktop icons such that later clicks on the Desktop always activates ahk_class Progman?
Or is there some other #IfWinActive / #If condition that doesn't use title/class/exe but still reliably detect the Desktop?

To test the issue
- open AutoHotkey Window Spy and uncheck "Follow Mouse"
- run the script below and press press 4 to hide icons
- Switch to any other window
- Click the Desktop

Expected result is Window Spy should now show ahk_class Progman ahk_exe explorer.exe as active window after the click.
But Window Spy sometimes instead shows no active window. Clicking on the Desktop again then sometimes detects Progman as active, sometimes not.

Code: Select all

#SingleInstance force
;Toggle Desktop Icons on/off
ControlGet, DesktopHwnd, Hwnd,, SysListView321, ahk_class Progman
If DllCall("IsWindowVisible", UInt, DesktopHwnd)
  Control, Hide,, , ahk_id %DesktopHwnd%
  Control, Show,, , ahk_id %DesktopHwnd%

Esc:: ExitApp