#Region    ;************ Includes ************
#include <Misc.au3>
#include <GUIConstantsEx.au3>
#EndRegion ;************ Includes ************

#include <Misc.au3>
#include <MsgBoxConstants.au3>
If _Singleton(@ScriptName, 1) Then
   ;erstes mal start
	ControlSend ( "OBS 21.1.0 (64bit, windows) - Profil: Unbenannt - Szenen: Unbenannt", "", "[CLASS:Qt5QWindowIcon; INSTANCE:1]", "+{f12}" )      ;start recording
	HotKeySet("+{f3}", "_replay")
	Send ("+{f3}")
	AdlibRegister("_StopRecord", 1000*60*1)
	 ; Juhu, ich bin allein...
    _Main()
Else
      ; zweites mal start
	ControlSend ( "OBS 21.1.0 (64bit, windows) - Profil: Unbenannt - Szenen: Unbenannt", "", "[CLASS:Qt5QWindowIcon; INSTANCE:1]", "+{f12}" )      ;start recording
    Send ("+{f4}")
	 ; Es läuft bereits eine Instanz...  HÄ DAS IST DOCH VERTAUSCHT????????????????????????????????????????????????????????????????????????????????????????
    Local $hWnd = WinGetHandle(@ScriptName), $hCtrl = ControlGetHandle($hWnd, '', '[CLASS:Static; INSTANCE:1]')
    If IsHWnd($hCtrl) Then
        ControlSetText($hCtrl, '', '', 'Verpiss dich...')
        ControlClick($hCtrl, '', '') ; Klopf, klopf... etwas Zeit zum (Lesen des neuen Textes und) Beenden des Scriots geben,
        If Not WinWaitClose($hWnd, '', 5) Then ; 5 Sekunden...  damit es evtl. noch Daten speichern kann.
            WinClose($hWnd) ; Was, der will nicht spuren? Dann eben so...
        EndIf
    EndIf
EndIf




HotKeySet("+{f4}", "_ExtendTime")
While 1
    Sleep(20)
WEnd

Func _StopRecord()
	ControlSend ( "OBS 21.1.0 (64bit, windows) - Profil: Unbenannt - Szenen: Unbenannt", "", "[CLASS:Qt5QWindowIcon; INSTANCE:1]", "+{f11}" )
    Exit
	WinWaitClose
 EndFunc

Func _ExtendTime()
    $iTime = 1                              ;stop recording after 1 minutes
    AdlibRegister("_StopRecord", 1000*60*$iTime)
 EndFunc

Func _replay()
ControlSend ( "OBS 21.1.0 (64bit, windows) - Profil: Unbenannt - Szenen: Unbenannt", "", "[CLASS:Qt5QWindowIcon; INSTANCE:1]", "+{f6}" )
EndFunc
Func _Exit()
   Exit
EndFunc


Func _Main()
    #Region - GUI Create
    Local $hGUI = GUICreate(@ScriptName)
    GUISetBkColor(0x280000)
    Local $idLabel_Singleton = GUICtrlCreateLabel('Mich gibt es nur 1x ;-)', 10, 10, 250)
    GUICtrlSetFont(-1, 14)
    GUICtrlSetColor(-1, 0xFF0000)
    GUISetState()
    #EndRegion
    #Region - GUI SwitchLoop
    While True
        Switch GUIGetMsg()            ;switch ändert ereignis je nach case
            Case $GUI_EVENT_CLOSE
                Exit
            Case $idLabel_Singleton
                Sleep(150)     ; 	in diesem script muss der wert so niedrig bleiben
                GUICtrlSetData($idLabel_Singleton, 'Ja, ich gehe ja schon...')
                Sleep(150)
                Exit
;~             Case
;~             Case
;~             Case
;~             Case Else
        EndSwitch
    WEnd
    #EndRegion
EndFunc
