     Return
 
 ; }}}
-; Wireless/internet connections {{{
-
-; Show Wireless IP4 properties
-#w::
-    Run ::{7007acc7-3202-11d1-aad2-00805fc1270e},, max
-    WinWaitActive, Network Connections
-    MiddleWindow()
-    Send {Space}w{AppsKey}
-    Sleep 250
-    Send {Down 9}{Enter}
-    WinWaitActive, Wi-Fi Fijo Properties
-    Sleep 300
-    Send {Down 9}
-    ControlClick, P&roperties,,,,3
-    Return
-
-; Automatically set Network settings (requires running autohotkey as admin)
-; FIXME: If run as admin startup script is not executed
-^#n::
-    {
-    SetTimer, ChangeButtonNames, 50
-    Msgbox, 4, Static or Automatic IP Address, Do you want to use a static IP address?
-    IfMsgBox Yes
-    {
-    Run, %comspec% /c netsh interface ip set address "Wi-Fi Fijo" source=static address=192.168.50.130 mask=255.255.255.0 gateway=192.168.50.1
-    Run, %comspec% /c netsh interface ip set dnsservers "Wi-Fi Fijo" source=static address=192.168.50.3 primary
-    }
-	else
-    {
-    Run, %comspec% /c netsh interface ip set address "Wi-Fi Fijo" source=dhcp
-    Run, %comspec% /c netsh interface ip set dnsservers "Wi-Fi Fijo" source=dhcp
-    }
-    }
-    Return
-
-; Helper function to change button names
-ChangeButtonNames:
-    IfWinNotExist, Static or Automatic IP Address
-        Return
-    SetTimer, ChangeButtonNames, off
-    WinActivate
-    ControlSetText, Button1, &Static (AF)
-    ControlSetText, Button2, &Automatic
-    Return
-
-; }}}
 ; Miscellaneous {{{
 
-; Close applications Unix/Mac style
-^q:: Send !{F4}
+; Close applications and window Mac style
+#q:: Send !{F4}
+#w:: Send ^w
 
 ; Make Capslock a Tab key (but allow to retain Capslock with Shift+Capslock)
 +Capslock::Capslock

^#4:: BottomRightQuarterfWindow()
^#5:: MiddleWindow()

; TODO: Send window to next monitor

; }}}
; Run or activate app and kill process {{{

    Return

 ; }}}
; Multiple monitors handling {{{

GetCurrentMonitor()
{
  SysGet, numberOfMonitors, MonitorCount
  WinGetPos, winX, winY, winWidth, winHeight, A
  winMidX := winX + winWidth / 2
  winMidY := winY + winHeight / 2
  Loop %numberOfMonitors%
  {
    SysGet, monArea, Monitor, %A_Index%
    if (winMidX > monAreaLeft && winMidX < monAreaRight && winMidY < monAreaBottom && winMidY > monAreaTop)
      Return A_Index
  }
}

; }}}
; Window handling {{{

LeftHalfWindow()
{
    currMon := GetCurrentMonitor()
	SysGet, area, MonitorWorkArea, %currMon%
	w:=((areaRight-areaLeft)/2)
	h:=(areaBottom-areaTop)
    x := 0
    y := 0
    if (currMon = 2) {
        x := -1920
        y := -300
    }

    WinRestore, A
    WinMove, A, , x, y,%w%,%h%
}

RightHalfWindow()
{
    currMon := GetCurrentMonitor()
	SysGet, area, MonitorWorkArea, %currMon%
	w:=((areaRight-areaLeft)/2)
	h:=(areaBottom-areaTop)
    x := w
    y := 0
    if (currMon = 2) {
        x := w -1920
        y := -300
    }

	WinRestore, A
	WinMove, A, , x, y, w, h
}

TopHalfWindow()
{
    currMon := GetCurrentMonitor()
	SysGet, area, MonitorWorkArea, %currMon%
	w:=(areaRight-areaLeft)
	h:=((areaBottom-areaTop)/2)
    x := 0
    y := 0
    if (currMon = 2) {
        x := -1920
        y := -300
    }

	WinRestore, A
	WinMove, A, , x, y, w, h
}

BottomHalfWindow()
{
    currMon := GetCurrentMonitor()
	SysGet, area, MonitorWorkArea, %currMon%
	w:=(areaRight-areaLeft)
	h:=((areaBottom-areaTop)/2)
    x := 0
    y := h
    if (currMon = 2) {
        x := -1920
        y := h -300
    }

	WinRestore, A
	WinMove, A, , x, y, w, h
}

TopLeftQuarterfWindow()
{
    currMon := GetCurrentMonitor()
	SysGet, area, MonitorWorkArea, %currMon%
	w:=((areaRight-areaLeft)/2)
	h:=((areaBottom-areaTop)/2)
    x := 0
    y := 0
    if (currMon = 2) {
        x := -1920
        y := -300
    }

	WinRestore, A
	WinMove, A, , x, y,%w%,%h%
}

BottomLeftQuarterfWindow()
{
    currMon := GetCurrentMonitor()
	SysGet, area, MonitorWorkArea, %currMon%
	w:=((areaRight-areaLeft)/2)
	h:=((areaBottom-areaTop)/2)
    x := 0
    y := h
    if (currMon = 2) {
        x := -1920
        y := h -300
    }

	WinRestore, A
	WinMove, A, , x, y, w, h
}

TopRightQuarterfWindow()
{
    currMon := GetCurrentMonitor()
	SysGet, area, MonitorWorkArea, %currMon%
	w:=((areaRight-areaLeft)/2)
	h:=((areaBottom-areaTop)/2)
    x := w
    y := 0
    if (currMon = 2) {
        x := w -1920
        y := -300
    }

	WinRestore, A
	WinMove, A, , x, y, w, h
}

BottomRightQuarterfWindow()
{
    currMon := GetCurrentMonitor()
	SysGet, area, MonitorWorkArea, %currMon%
	w:=((areaRight-areaLeft)/2)
	h:=((areaBottom-areaTop)/2)
    x := w
    y := h
    if (currMon = 2) {
        x := w -1920
        y := h -300
    }

	WinRestore, A
	WinMove, A, , x, y, w, h
}

MiddleWindow()
{
    currMon := GetCurrentMonitor()
	SysGet, area, MonitorWorkArea, %currMon%
	w:=((areaRight-areaLeft)/2)
	h:=((areaBottom-areaTop)/2)
    x := w / 2
    y := h /2
    if (currMon = 2) {
        x := (-1920 - w) / 2
        y := (-300 / 2)
    }

	WinRestore, A
	WinMove, A, , x, y, w, h
}

; Mapppings
#Left::  LeftHalfWindow()  ; Default in Windows 10 is #Left
#Right:: RightHalfWindow() ; Default in Windows 10 is #Right
^#Up::   TopHalfWindow()
^#Down:: BottomHalfWindow()
^#1:: TopLeftQuarterfWindow()
