Here's my take on this. I toggle the "super-hidden" files, since I have normal hidden files show by default. "Super-hidden" are files that have the System and Hidden attributes set. You can easily change this to just toggle "regular" hidden files.
I use a scancode because of the way I have a few other things set up. Long story short, it's for the Windows key on my keyboard. Feel free to change that for your use.
The main thing I didn't like about the solutions I see on here is that they only refresh the "active" window. Since Hidden and SuperHidden actually apply to all Explorer windows, I wanted them *all* to refresh when I toggled it. So it refreshes all of the specified
classes (including the desktop), not just the active window ID.
You might have to adjust the second parameter of PostMessage for different Windows versions (41504 is working for me on Windows 7 x64).
; --- TOGGLE "SUPERHIDDEN" FILES ---
SC06E & H Up::
WinGetClass, ActiveWindowClass, A
WClasses := "Progman CabinetWClass ExploreWClass"
IfNotInString, WClasses, %ActiveWindowClass%
Return
ROOTKEY := "HKEY_CURRENT_USER"
SUBKEY := "Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
RegRead, ShowSuperHidden_Status, %ROOTKEY%, %SUBKEY%, ShowSuperHidden
If ShowSuperHidden_Status = 0
ShowSuperHidden_Status = 1
Else
ShowSuperHidden_Status = 0
RegWrite, REG_DWORD, %ROOTKEY%, %SUBKEY%, ShowSuperHidden, %ShowSuperHidden_Status%
Loop, Parse, WClasses, %A_Space%
PostMessage, 0x111, 41504,,, ahk_class %A_LoopField%
Return