So I rewrote this code I wrote in a very professional manner.

#SingleInstance Force
if IsLabel("PreferenceSettings") = 0
{
msgbox , , Welcome!, Hello! I hope you enjoy this script!`n`nWhat it does: press the hotkey to turn on auto-hiding for the active window. The window will hide when the cursor is not over the window. It will return when you move the cursor to a predefined area on the edge of the screen. Hide as many windows as you want, and press the hotkey again with a window selected to turn auto-hiding off.`n`nNote: you must run this setup wizard as a .ahk file and not as a .exe file.
inputbox, MouseoverWidth, Welcome!, To start`, please enter the size in pixels of the predefined mouseover area. This box is 300x200 pixels. Suggested - 200,,300,200,,,,,200
if ErrorLevel <> 0
exitapp
loop
{
inputbox, UserHotkey, Welcome!, Please type the hotkey you would like to use in AutoHotkey format:`nCTRL = ^`nWindows = #`nAlt = !`nShift = +`nTo see more`, type help.,,300,250,,,,,#j
if ErrorLevel <> 0
exitapp
If (UserHotkey = "help") or (UserHotkey = "Help")
{
run "http://www.autohotkey.com/docs/KeyList.htm"
continue
}
break
}
inputbox, UserUnhideHotkey, Welcome!, Please type a hotkey to unhide all hidden windows. Suggested - SHIFT + Previously defined hotkey,,300,200,,,,,+%UserHotkey%
if ErrorLevel <> 0
exitapp
inputbox, UserSnapHotkey, Welcome!, Please type a hotkey to snap the window to the closest screen corner.,,300,200,,,,,+#.
if ErrorLevel <> 0
exitapp
Msgbox 4, Welcome!, Would you like to use graphical elements?
if ErrorLevel <> 0
exitapp
IfMsgBox No
gfx := 0
else {
gfx := 1
loop
{
inputbox, HideColor, Welcome!, Please enter a color that will indicate auto-hiding has been turned on`, in hexadecimal format. Suggested - Green (00FF00)`n`nFor help with hexadecimal colors`, type help.,,300,200,,,,,00FF00
if ErrorLevel <> 0
{
gfx := 0
break
}
If (Hidecolor = "help") or (Hidecolor = "Help")
{
run "http://www.autohotkey.com/docs/commands/Progress.htm#colors"
continue
}
break
}
inputbox, UnhideColor, Welcome!, Please enter a color that will indicate auto-hiding has been turned off`, in hexadecimal format. Suggested - Red (FF0000),,300,200,,,,,FF0000
if ErrorLevel <> 0
gfx := 0
inputbox, MinimizeColor, Welcome!, Please enter a color that will appear when a window auto-hides`, in hexadecimal format. Suggested - Blue (0000FF),,300,200,,,,,0000FF
if ErrorLevel <> 0
gfx := 0
inputbox, GUIThickness, Welcome!, Please enter the desired width in pixels of the graphical elements. A higher number will lead to more conspicuous graphics. Suggested - 8,,300,200,,,,,8
if ErrorLevel <> 0
gfx := 0
}
Msgbox 4, Welcome!, Would you like to set up some programs to be auto-hidden on default?
if ErrorLevel <> 0
exitapp
n := 0
IfMsgBox Yes
{
loop
{
inputbox, FilePath, Welcome!, Please enter the path (e.g. C:\My Documents\My File.extension or http://www.website.com/) of a%nother% window you would like to have open at startup`, then wait for the program to load. Press cancel to skip this step.,,400,200
if ErrorLevel <> 0
break
run, %FilePath%, , UseErrorLevel
if ErrorLevel
{
Msgbox, , Welcome!, Invalid filepath. Please try again.
continue
}
sleep 2000
wingettitle, ActiveTitle, A
Msgbox 4, Welcome!, %ActiveTitle%`n`nIs this correct?
IfMsgBox No
Continue
Winget, NewHWND, ID, %ActiveTitle%
wingetpos, x, y, Width, Height, ahk_id %NewHWND%
Msgbox, , Welcome!, Please position and size the window the way you would like it to appear by default`, then press OK when you are finished.
wingetpos, x, y, Width, Height, ahk_id %NewHWND%
loop
{
inputbox, Commands, Welcome!, Would you like to send any commands to this window when it opens? E.g. CTRL + END to go to the end of a document.`n`nYou must enter them in AutoHotkey format`, for example ^{end}. For help type help.`n`nTo skip this step press cancel.,,400,250
if (Commands = "help") or (Commands = "Help")
{
Commands =
run, http://www.autohotkey.com/docs/commands/Send.htm
continue
}
break
}
Msgbox 4, Welcome!, Save this configuration?
IfMsgBox Yes
{
n++
winclose ahk_id %NewHWND%
min := 10000
if (x < min)
min := x, ScreenEdge := "Left"
if (y < min)
min := y, ScreenEdge := "Top"
if ((A_ScreenWidth - 1 - x - Width) < min)
min := A_ScreenWidth - 1 - x - Width, ScreenEdge := "Right"
if ((A_ScreenHeight - 1 - y - Height) < min)
ScreenEdge := "Bottom"
WindowsOnStartUp =
(
%WindowsOnStartUp%run, %FilePath%
winwaitactive %ActiveTitle%
Winget, NewHWND, ID, %ActiveTitle%
Winmove, ahk_id `%NewHWND`%, , %x%, %y%, %Width%, %Height%
HWND%n% := NewHWND
Active%n% := 1
Screenedge%n% = %ScreenEdge%
)
if Commands
WindowsOnStartUp = %WindowsOnStartUp%sleep 1000`nsend %Commands%`n
if (nother = "nother")
s = s
nother = nother
continue
}
}
Msgbox, , Welcome!, You have configured %n% window%s% to run on startup.
}
Msgbox 518, Welcome!, All set! The script will now close and re-open with your saved preferences.`n`nTo edit these preferences at any time`, you can edit the .ahk file and scroll to the bottom to find the PreferenceSettings label. You can edit these manually`, or delete the entire section and restart the script to reengage the wizard.
IfMsgBox Cancel
Exitapp
IfMsgBox TryAgain
reload
FileAppend,
(
PreferenceSettings:
%WindowsOnStartUp%n := %n%
MouseoverWidth := %MouseoverWidth%
UserHotkey = %UserHotkey%
UserUnhideHotkey = %UserUnhideHotkey%
UserSnapHotkey = %UserSnapHotkey%
gfx := %gfx%
HideColor = %HideColor%
UnhideColor = %UnhideColor%
Color = %HideColor%
MinimizeColor = %MinimizeColor%
GUIThickness := %GUIThickness%
return
), %A_ScriptFullPath%
reload
}
;=============================================End of Setup Section===================================================
;You can delete everything above this point after you run it the first time if you like, although it makes reconfiguration easier (delete the PreferenceSettings label and run again)
DetectHiddenWindows, on
#SingleInstance Force
SetWinDelay 10
SetKeyDelay 0
Coordmode Mouse
OnExit, ForceExit
Exiting := 0
GotoLabel = PreferenceSettings
Gosub %GotoLabel%
Hotkey, %UserHotkey%, AutoHide
Hotkey, %UserUnhideHotkey%, UnhideAll
Hotkey, %UserSnapHotkey%, SnapWindow
gosub ListHiddenWindows
settimer, Mouseover, 250
Mouseover:
MouseGetPos, MouseX, MouseY
loop %n%
{
ifwinnotexist % "ahk_id " . HWND%A_Index%
{
gosub ClearName
return
}
if Active%A_Index%
{
wingetpos, x, y, Width, Height, % "ahk_id " . HWND%A_Index%
if (x <> x%A_Index%) or (y <> y%A_Index%) or (Width <> Width%A_Index%) or (Height <> Height%A_Index%)
{
Gosub GetScreenEdge
x%A_Index% := x, y%A_Index% := y, Width%A_Index% := Width, Height%A_Index% := Height
}
Gosub % "Active" . ScreenEdge%A_Index%
} else
GoSub % "Hidden" . ScreenEdge%A_Index%
}
return
GetScreenEdge:
min := 10000
if (x < min)
min := x, ScreenEdge%A_Index% := "Left"
if (y < min)
min := y, ScreenEdge%A_Index% := "Top"
if ((A_ScreenWidth - 1 - x - Width) < min)
min := A_ScreenWidth - 1 - x - Width, ScreenEdge%A_Index% := "Right"
if ((A_ScreenHeight - 1 - y - Height) < min)
ScreenEdge%A_Index% := "Bottom"
if gfx = 0
return
gui color, %Color%
gui 2:color, %Color%
gui 1:+ToolWindow -SysMenu -Caption +AlwaysOnTop
gui 2:+ToolWindow -SysMenu -Caption +AlwaysOnTop
if (ScreenEdge%A_Index% = "Top")
{
v := y - GUIThickness
if (y > 0)
Gui 1:show, H%GUIThickness% W%Width% X%x% Y%v% NA
Gui 2:show, H%GUIThickness% W%Width% X%x% Y0 NA
}
else if (ScreenEdge%A_Index% = "Left")
{
v := x - GUIThickness
if (x > 0)
Gui 1:show, W%GUIThickness% H%Height% X%v% Y%y% NA
Gui 2:show, W%GUIThickness% H%Height% X0 Y%y% NA
}
else if (ScreenEdge%A_Index% = "Right")
{
v := x + Width
if (v < A_ScreenWidth - 1)
Gui 1:show, W%GUIThickness% H%Height% X%v% Y%y% NA
v := A_ScreenWidth - GUIThickness
Gui 2:show, W%GUIThickness% H%Height% X%v% Y%y% NA
}
else
{
v := y + Height
if (v < A_ScreenHeight - 1)
Gui 1:show, H%GUIThickness% W%Width% X%x% Y%v% NA
v := A_ScreenHeight - GUIThickness
Gui 2:show, H%GUIThickness% W%Width% X%x% Y%v% NA
}
sleep 100
gui 1:destroy
gui 2:destroy
return
HiddenTop:
if MouseY <> 0
return
if (MouseX < MouseoverLocation%A_Index%) or (MouseX > (MouseoverLocation%A_Index% + MouseoverWidth))
return
winshow, % "ahk_id " . HWND%A_Index%
winactivate % "ahk_id " . HWND%A_Index%
Active%A_Index% = 1
gosub ListHiddenWindows
return
HiddenLeft:
if MouseX <> 0
return
if (MouseY < MouseoverLocation%A_Index%) or (MouseY > (MouseoverLocation%A_Index% + MouseoverWidth))
return
winshow, % "ahk_id " . HWND%A_Index%
winactivate % "ahk_id " . HWND%A_Index%
Active%A_Index% = 1
gosub ListHiddenWindows
return
HiddenRight:
if (MouseX <> A_ScreenWidth - 1)
return
if (MouseY < MouseoverLocation%A_Index%) or (MouseY > (MouseoverLocation%A_Index% + MouseoverWidth))
return
winshow, % "ahk_id " . HWND%A_Index%
winactivate % "ahk_id " . HWND%A_Index%
Active%A_Index% = 1
gosub ListHiddenWindows
return
HiddenBottom:
if (MouseY <> A_ScreenHeight - 1)
return
if (MouseX < MouseoverLocation%A_Index%) or (MouseX > (MouseoverLocation%A_Index% + MouseoverWidth))
return
winshow, % "ahk_id " . HWND%A_Index%
winactivate % "ahk_id " . HWND%A_Index%
Active%A_Index% = 1
gosub ListHiddenWindows
return
ActiveTop:
if (MouseY < y + Height)
if (x < MouseX) and (MouseX < x + Width)
return
winhide % "ahk_id " . HWND%A_Index%
ifwinactive % "ahk_id " . HWND%A_Index%
send !{esc}
Active%A_Index% = 0
MouseoverLocation%A_Index% := (Width - MouseoverWidth) * x / (A_ScreenWidth - Width) + x
if (MouseoverLocation%A_Index% < -100)
MouseoverLocation%A_Index% := -100
if (MouseoverLocation%A_Index% > A_ScreenWidth - 101)
MouseoverLocation%A_Index% := A_ScreenWidth - 101
GUIX := x
XIncrement := (MouseoverLocation%A_Index% - x) / 10
GUIY := y + Height
YIncrement := -(y + Height) / 10
GUIWidth := Width
GUIHeight := GUIThickness
WidthIncrement := (Width - MouseoverWidth) / 10
HeightIncrement := 0
gosub MinimizeGUI
gosub ListHiddenWindows
return
ActiveLeft:
if (MouseX < x + Width)
if (y < MouseY) and (MouseY < y + Height)
return
winhide % "ahk_id " . HWND%A_Index%
ifwinactive % "ahk_id " . HWND%A_Index%
send !{esc}
Active%A_Index% = 0
MouseoverLocation%A_Index% := (Height - MouseoverWidth) * y / (A_ScreenHeight - Height) + y
if (MouseoverLocation%A_Index% < -100)
MouseoverLocation%A_Index% := -100
if (MouseoverLocation%A_Index% > A_ScreenHeight - 101)
MouseoverLocation%A_Index% := A_ScreenHeight - 101
GUIX := x + Width
XIncrement := -(x + Width) / 10
GUIY := y
YIncrement := (MouseoverLocation%A_Index% - y) / 10
GUIWidth := GUIThickness
GUIHeight := Height
WidthIncrement := 0
HeightIncrement := (Height - MouseoverWidth) / 10
gosub MinimizeGUI
gosub ListHiddenWindows
return
ActiveRight:
if (MouseX > x)
if (y < MouseY) and (MouseY < y + Height)
return
winhide % "ahk_id " . HWND%A_Index%
ifwinactive % "ahk_id " . HWND%A_Index%
send !{esc}
Active%A_Index% = 0
MouseoverLocation%A_Index% := (Height - MouseoverWidth) * y / (A_ScreenHeight - Height) + y
if (MouseoverLocation%A_Index% < -100)
MouseoverLocation%A_Index% := -100
if (MouseoverLocation%A_Index% > A_ScreenHeight - 101)
MouseoverLocation%A_Index% := A_ScreenHeight - 101
GUIX := x - GUIThickness
XIncrement := (A_ScreenWidth - x) / 10
GUIY := y
YIncrement := (MouseoverLocation%A_Index% - y) / 10
GUIWidth := GUIThickness
GUIHeight := Height
WidthIncrement := 0
HeightIncrement := (Height - MouseoverWidth) / 10
gosub MinimizeGUI
gosub ListHiddenWindows
return
ActiveBottom:
if (MouseY > y)
if (x < MouseX) and (MouseX < x + Width)
return
winhide % "ahk_id " . HWND%A_Index%
ifwinactive % "ahk_id " . HWND%A_Index%
send !{esc}
Active%A_Index% = 0
MouseoverLocation%A_Index% := (Width - MouseoverWidth) * x / (A_ScreenWidth - Width) + x
if (MouseoverLocation%A_Index% < -100)
MouseoverLocation%A_Index% := -100
if (MouseoverLocation%A_Index% > A_ScreenWidth - 101)
MouseoverLocation%A_Index% := A_ScreenWidth - 101
GUIX := x
XIncrement := (MouseoverLocation%A_Index% - x) / 10
GUIY := y - GUIThickness
YIncrement := (A_ScreenHeight - y) / 10
GUIWidth := Width
GUIHeight := GUIThickness
WidthIncrement := (Width - MouseoverWidth) / 10
HeightIncrement := 0
gosub MinimizeGUI
gosub ListHiddenWindows
return
MinimizeGUI:
gui 3:color, %MinimizeColor%
gui 3:+ToolWindow -SysMenu -Caption +AlwaysOnTop
loop % gfx * 11
{
gui 3:show, w%GUIWidth% h%GUIHeight% x%GUIX% y%GUIY% NA
GUIX += XIncrement
GUIY += YIncrement
GUIWidth -= WidthIncrement
GUIHeight -= HeightIncrement
sleep %A_Index%
}
gui 3:destroy
return
ForceExit:
Exiting := 1
goto UnhideAll
return
UnhideAll:
loop %n%
{
winshow % "ahk_id " . HWND%A_Index%
winactivate % "ahk_id " . HWND%A_Index%
}
n := 0
if Exiting
exitapp
menu, tray, tip, AutoHide Windows
return
AutoHide:
ActiveWindow := WinExist("A")
loop % n + 1
{
if (ActiveWindow = HWND%A_Index%)
{
Color := UnhideColor
gosub GetScreenEdge
Color := HideColor
gosub ClearName
return
}
if (A_Index = n + 1)
{
HWND%A_Index% := ActiveWindow
Active%A_Index% = 1
}
}
n++
gosub ListHiddenWindows
return
ClearName:
c := A_Index
loop % n - c
{
d := c + 1
Active%c% := Active%d%
HWND%c% := HWND%d%
MouseoverLocation%c% := MouseoverLocation%d%
ScreenEdge%c% := ScreenEdge%d%
x%c% := x%d%
y%c% := y%d%
Width%c% := Width%d%
Height%c% := Height%d%
c++
}
HWND%n% =
x%n% =
n--
gosub ListHiddenWindows
return
ListHiddenWindows:
if n = 0
{
menu, tray, tip, AutoHide Windows
return
}
TitleSum := "Windows AutoHidden:"
loop %n%
{
if Active%A_Index% = 1
continue
WinGetTitle, title, % "ahk_id " . HWND%A_Index%
TitleSum := TitleSum . "`n" . title
}
if (TitleSum = "Windows AutoHidden:")
menu, tray, tip, AutoHide Windows
else
menu, tray, tip, %TitleSum%
return
SnapWindow:
Already = 0
ActiveHWND := WinActive("A")
Loop % n + 1
{
if (A_Index = n + 1)
{
HWND%A_Index% := ActiveHWND
Active%A_Index% = 1
n++
wingetpos, x, y, Width, Height, % "ahk_id " . HWND%A_Index%
Gosub GetScreenEdge
gosub ListHiddenWindows
}
If (ActiveHWND = HWND%A_Index%)
If not Active%A_Index%
return
else {
If (ScreenEdge%A_Index% = "Top") {
If (x%A_Index% < A_ScreenWidth - x%A_Index% - Width%A_Index% - 1)
WinMove, % "ahk_ID " . HWND%A_Index%, , -1, -2
Else
WinMove, % "ahk_ID " . HWND%A_Index%, , A_ScreenWidth - Width%A_Index%, -2
} Else If (ScreenEdge%A_Index% = "Left") {
If (y%A_Index% < A_ScreenHeight - y%A_Index% - Height%A_Index% - 1)
WinMove, % "ahk_ID " . HWND%A_Index%, , -2, -1
Else {
WinMove, % "ahk_ID " . HWND%A_Index%, , -2, A_ScreenHeight - Height%A_Index% + 1
WinSet, alwaysontop, ON, % "ahk_ID " . HWND%A_Index%
}
} Else If (ScreenEdge%A_Index% = "Right") {
If (y%A_Index% < A_ScreenHeight - y%A_Index% - Height%A_Index% - 1)
WinMove, % "ahk_ID " . HWND%A_Index%, , A_ScreenWidth - Width%A_Index% + 2, -1
Else {
WinMove, % "ahk_ID " . HWND%A_Index%, , A_ScreenWidth - Width%A_Index% + 2, A_ScreenHeight - Height%A_Index% + 1
WinSet, alwaysontop, ON, % "ahk_ID " . HWND%A_Index%
}
} Else If (ScreenEdge%A_Index% = "Bottom") {
If (x%A_Index% < A_ScreenWidth - x%A_Index% - Width%A_Index% - 1)
WinMove, % "ahk_ID " . HWND%A_Index%, , -1, A_ScreenHeight - Height%A_Index% + 2
Else
WinMove, % "ahk_ID " . HWND%A_Index%, , A_ScreenWidth - Width%A_Index% + 1, A_ScreenHeight - Height%A_Index% + 2
WinSet, alwaysontop, ON, % "ahk_ID " . HWND%A_Index%
}
Gosub GetScreenEdge
return
}
}
return
;-----------------Special Winclose Key (to avoid closing hidden windows)------------
;This shouldn't be necessary, but I like to have a pause::winclose, A key anyway, and it was messing up if I didn't implement it like this
pause::
WindowToClose := WinExist("A")
loop %n%
if (WindowToClose = HWND%A_Index%)
if (0 = Active%A_Index%)
{
winclose Program Manager
return
}
send !{f4}{pause up}
return
;==============================User Defined Preferences===========================
Here's the code. The first part allows you to customize the script. Load it up and take it for a spin
Edit - I added a key, WIN + SHIFT + . (or caret, so I remember "to the side") combo that will move the current window to the nearest screen corner, autohide it if it isn't already hidden, and set it to "Always on top" if it is above the taskbar. (You'll need some kind of key to undo always on top if you want to un-autohide it.)
Ask me any questions you might have.
Ben




