First do not use a large sleep for any time sensitive application.
While sleep is active pretty much everything else is blocked.
Timer is the normal way to handle this, but I like to use Adlibregister()
I just threw this together as an example.
Recording starts when script starts, default of 15 minutes, if you press F1 you can enter a new stop time (does not append so if you had 5 minutes left and wanted to add 15 minutes you would say 20 minutes)
AdlibRegister("_StopRecord", 1000*60*15)
HotKeySet("{F1}", "_ExtendTime")
;ControlSend ( "OBS 21.1.0 (64bit, windows) - Profil: Unbenannt - Szenen: Unbenannt", "", "[CLASS:Qt5QWindowIcon; INSTANCE:1]", "+{f12}" ) start recording
MsgBox(0, "", "Start Recording")
While 1
Sleep(10)
WEnd
Func _StopRecord()
;ControlSend ( "OBS 21.1.0 (64bit, windows) - Profil: Unbenannt - Szenen: Unbenannt", "", "[CLASS:Qt5QWindowIcon; INSTANCE:1]", "+{f11}" )
MsgBox(0, "", "Recording Ended")
Exit
EndFunc
Func _ExtendTime()
$iTime = InputBox("Extend Recording", "Number of Minutes Record", "15")
AdlibRegister("_StopRecord", 1000*60*$iTime)
EndFunc