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
#NoEnv #SingleInstance force 4:: ;Toggle Desktop Icons on/off ControlGet, DesktopHwnd, Hwnd,, SysListView321, ahk_class Progman If DllCall("IsWindowVisible", UInt, DesktopHwnd) Control, Hide,, , ahk_id %DesktopHwnd% else Control, Show,, , ahk_id %DesktopHwnd% Return Esc:: ExitApp