#include <Misc.au3>
Opt("WinWaitDelay",  300)
Opt("WinDetectHiddenText",3)
Opt("MouseCoordMode",  1)
Opt("SendKeyDelay",   20)
Opt("MustDeclareVars", 1)

Global $hdll=DllOpen("user32.dll");open the DLL used in _IsPressed
Global $ClickState=0;0 indicates left mouse button is "up", 1 indicates left mouse button is "down".
DIM $POS, $ShellTray, $CurrentWin, $DELTA, $DELTAleft, $DELTAright, $SCREENoffset, $RAND, $CurrentWinCLICK, $TOGGLE
$DELTAleft =  0
$DELTAright =  0
$RAND   =  6
$TOGGLE =  1
$CurrentWinCLICK = 0

InitHotKeys()

$ShellTray = WinGetPos ( "[CLASS:Shell_TrayWnd]")
IF (($ShellTray[1]+8) < @DesktopHeight) THEN
	IF (($ShellTray[0]+2) < @DesktopWidth) THEN
		$DELTAleft = $ShellTray[3] - 2
	ELSE
		$DELTAright = $ShellTray[3] - 2
	ENDIF
ENDIF
	
WHILE 1
	$POS = MouseGetPos()
	$CurrentWin = WinGetPos ( "[ACTIVE]")
	
	IF ((_IsPressed("01",$hdll) = 1) AND ($CurrentWinCLICK = 0)) THEN
		IF ((($POS[1]-$CurrentWin[1]) < 22)  AND (MouseGetCursor() <> 11)) THEN
			IF ($POS[1] > $RAND) THEN															; Linksklick in Titelzeile
				$CurrentWinCLICK = 1
			ENDIF
			IF (_IsPressed("11",$hdll) = 1) THEN												; Switch
				MoveMyWinSwitch()
			ELSEIF (_IsPressed("12",$hdll) = 1) THEN											; TopMost
				MoveMyWinTopMost()
			ENDIF
		ELSE
			$CurrentWinCLICK = 0
		ENDIF
	ENDIF
	
	IF ($CurrentWinCLICK = 1) THEN
		$POS = MouseGetPos()
		$CurrentWin = WinGetPos ( "[ACTIVE]")
		IF (($POS[1] < $RAND) AND ($CurrentWin[1] >= 0) AND (_IsPressed("10",$hdll) = 1)) THEN	; Beide Monitore
			MouseUp("left")
			MoveMyWinBoth()
			$CurrentWinCLICK = 0
		ELSE
			IF ($POS[0] < @DesktopWidth) THEN													; linker Monitor
				$DELTA        = $DELTAleft
				$SCREENoffset = 0
			ELSE																				; rechter Monitor
				$DELTA        = $DELTAright
				$SCREENoffset = @DesktopWidth
			ENDIF
			
			IF (($POS[0]-$SCREENoffset) < $RAND) THEN											; links
				MouseUp("left")
				BlockInput(1)
				WinMove ("[ACTIVE]" ,"" ,$SCREENoffset ,0 ,@DesktopWidth/2 ,@DesktopHeight-$DELTA)
				$CurrentWinCLICK = 0
			ELSEIF ((($POS[0] - $SCREENoffset) > (@DesktopWidth-$RAND)) AND (($POS[0] - $SCREENoffset) < (@DesktopWidth))) THEN																					; rechts
				MouseUp("left")
				BlockInput(1)
				WinMove ("[ACTIVE]" ,"" ,$SCREENoffset+@DesktopWidth/2 ,0 ,@DesktopWidth/2 ,@DesktopHeight-$DELTA)
				$CurrentWinCLICK = 0
			ELSEIF (($POS[1] < $RAND) AND ($CurrentWin[1] >= 0)) THEN							; oben
				MouseUp("left")
				BlockInput(1)
				WinMove ("[ACTIVE]" ,"" ,$SCREENoffset ,0 ,@DesktopWidth ,@DesktopHeight-$DELTA)
				WinSetState("[ACTIVE]", "", @SW_MAXIMIZE) 
				$CurrentWinCLICK = 0
			ELSEIF ($POS[1] > (@DesktopHeight-$RAND)) THEN										; unten
				MouseUp("left")
				BlockInput(1)
				WinMove ("[ACTIVE]" ,"" ,$SCREENoffset ,@DesktopHeight/2 ,@DesktopWidth ,@DesktopHeight/2-$DELTA)
				$CurrentWinCLICK = 0
			ELSEIF (_IsPressed("01",$hdll) = 0) THEN											; Maustaste losgelassen
				$CurrentWinCLICK = 0
			ENDIF
		ENDIF
	ENDIF
		
	Sleep (100)
	BlockInput(0)
WEND

Func MoveMyWinMax()
	$CurrentWin = WinGetPos("[ACTIVE]")
	IF ($CurrentWin[0] < (@DesktopWidth-4)) THEN
		WinMove ("[ACTIVE]" ,"" ,0 ,0 ,default ,default)
		WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
	ELSE
		WinMove ("[ACTIVE]" ,"" ,@DesktopWidth ,0 ,default, default)
		WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
	ENDIF
EndFunc

Func MoveMyWinSwitch()
	$CurrentWin = WinGetPos("[ACTIVE]")
	WinSetState("[ACTIVE]", "", @SW_RESTORE)
	IF ($CurrentWin[0] > (@DesktopWidth-5)) THEN
		IF ($CurrentWin[0] < 0) THEN $CurrentWin[0] = 0
		WinMove ("[ACTIVE]" ,"" ,$CurrentWin[0]-@DesktopWidth ,$CurrentWin[1])
	ELSE
		WinMove ("[ACTIVE]" ,"" ,$CurrentWin[0]+@DesktopWidth ,$CurrentWin[1])
	ENDIF
	IF ($CurrentWin[1] = (-4)) THEN
		WinMove ("[ACTIVE]" ,"" ,default ,default ,@DesktopWidth ,@DesktopHeight)
		WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
	ENDIF
EndFunc

Func MoveMyWinBoth()
	WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)
	WinSetState("[ACTIVE]", "", @SW_RESTORE)
	WinMove ("[ACTIVE]" ,"" ,0 ,0 ,@DesktopWidth*2 ,@DesktopHeight-($DELTAleft+$DELTAright))
EndFunc

Func MoveMyWinLeft()
	$CurrentWin = WinGetPos("[ACTIVE]")
	WinSetState("[ACTIVE]", "", @SW_RESTORE)
	IF ($CurrentWin[0] < (@DesktopWidth-4)) THEN
		WinMove ("[ACTIVE]" ,"" ,0 ,0 ,@DesktopWidth/2 ,@DesktopHeight-$DELTAleft)
	ELSE
		WinMove ("[ACTIVE]" ,"" ,@DesktopWidth ,0 ,@DesktopWidth/2 ,@DesktopHeight-$DELTAright)
	ENDIF
EndFunc

Func MoveMyWinRight()
	$CurrentWin = WinGetPos("[ACTIVE]")
	WinSetState("[ACTIVE]", "", @SW_RESTORE)
	IF ($CurrentWin[0] < (@DesktopWidth-4)) THEN
		WinMove ("[ACTIVE]" ,"" ,@DesktopWidth/2 ,0 ,@DesktopWidth/2 ,@DesktopHeight-$DELTAleft)
	ELSE
		WinMove ("[ACTIVE]" ,"" ,@DesktopWidth+@DesktopWidth/2 ,0 ,@DesktopWidth/2 ,@DesktopHeight-$DELTAright)
	ENDIF
EndFunc

Func MoveMyWinTopMost()
	WinSetOnTop("[ACTIVE]","", $TOGGLE)
	$TOGGLE = NOT $TOGGLE
EndFunc

Func InitHotKeys()
	IF HotKeySet ("#0", "Info") = 0 THEN
		MsgBox(4096,"","Konnte Hotkey nicht registrieren.")
		EXIT
	ENDIF
	IF HotKeySet ("#1", "MoveMyWinLeft") = 0 THEN
		MsgBox(4096,"","Konnte Hotkey nicht registrieren.")
		EXIT
	ENDIF
	IF HotKeySet ("#2", "MoveMyWinRight") = 0 THEN
		MsgBox(4096,"","Konnte Hotkey nicht registrieren.")
		EXIT
	ENDIF
	IF HotKeySet ("#3", "MoveMyWinMax") = 0 THEN
		MsgBox(4096,"","Konnte Hotkey nicht registrieren.")
		EXIT
	ENDIF
	IF HotKeySet ("#4", "MoveMyWinSwitch") = 0 THEN
		MsgBox(4096,"","Konnte Hotkey nicht registrieren.")
		EXIT
	ENDIF
	IF HotKeySet ("#5", "MoveMyWinBoth") = 0 THEN
		MsgBox(4096,"","Konnte Hotkey nicht registrieren.")
		EXIT
	ENDIF
	IF HotKeySet ("#6", "MoveMyWinTopMost") = 0 THEN
		MsgBox(4096,"","Konnte Hotkey nicht registrieren.")
		EXIT
	ENDIF
EndFunc

Func Info()
	MsgBox(64+4096+262144,"Window Helper Info",  "Funktionen:" & @CRLF & @CRLF & " WIN + 1  (Fenster zum linken Rand ziehen   ) : links, halbe Breite" & @CRLF & " WIN + 2  (Fenster zum rechten Randziehen ) : rechts, halbe Breite" & @CRLF & " WIN + 3  (Fenster zum oberen Rand ziehen ) : maximieren" & @CRLF & "    -----      (Fenster zum unteren Rand ziehen): unten, halbe Höhe" & @CRLF & " WIN + 4  (Strg + Klick in Titelzeile                 ) : Fenster auf anderen Bildschirm" & @CRLF & " WIN + 5  (Shift + Fenster zum oberen Rand ziehen) : Spawn über beide Bildschirme" & @CRLF & " WIN + 6  (Alt + Klick in Titelzeile                   ) : Toggle TopMost" & @CRLF & " WIN + 0  (         = keine Mausgeste =          ) : Diese Information")
EndFunc

#region --- Internal functions Au5Recorder Start ---
Func _WinWaitActivate($title,$text,$timeout=0)
	WinWait($title,$text,$timeout)
	If Not WinActive($title,$text) Then WinActivate($title,$text)
	WinWaitActive($title,$text,$timeout)
EndFunc
#endregion --- Internal functions Au5Recorder End ---
