;Clock controlled START/STOP OBS recording ;Charles.R.Patton (at) IEEE.ORG ;ver. 1 3/11/219 ;tested with: AutoHotkey 1.1.30.01 ; OBS 23.0.2 (64-bit, windows) on Win10 ; 1) If your PC environment is different, Set these variables, "OBSpgm" and "OBSpath", to match your system so this program can start OBS: OBSpgm = obs64.exe OBSpath = C:\Program Files (x86)\obs-studio\bin\64bit\ ; it is important to let this program start OBS so that the PID is picked up correcty in order that the window focus can be returned to OBS when the START and STOP keys are sent by the program ;2) Set the HOTKEYs in OBS to match these current settings in this program ; "Start Recording" = PgUp ; "Stop Recording" = PgDn ; you can choose other hotkeys in OBS and by modifying the lines 127 & 141 according to the rules of AutoHotkey #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. ; #Warn ; Enable warnings to assist with detecting common errors. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. ;************************************* ;*************** get validated starttime starttxt = ( Input recording clock START time in 24 hour format HH:MM:SS or just a period delimiter HH.MM.SS ) loop { InputBox, StartTime,,%starttxt%,,400,160 Loop, parse, starttime, `:`. { ;MsgBox, Color number %A_Index% is %A_LoopField%. ; send %A_Index% is %A_LoopField% `n ;is trace for parse if A_Index = 1 starthr := A_LoopField if A_Index = 2 startmin := A_LoopField if A_Index = 3 startsec := A_LoopField } ;now check the data for validity if ((starthr >= 0) and (starthr <= 23) ;hour must be between 0 and 23 and (startmin >= 0) and (startmin <= 59) ;minute must be between 0 and 59 and (startsec >= 0) and (startsec <= 59)) ;second must be between 0 and 59 { break } else { InputBox, response,,%starttime% for START is invalid.`n Input Q to Quit otherwise try again } if (response = "Q") { exitapp ;quit the pgm if a Q given else return and reenter data } } ;************************************* ;*************** now get the validated STOP time stoptxt = ( Input recording clock STOP time in 24 hour format HH:MM:SS or just a period delimiter HH.MM.SS ) loop ;get validated stoptime { InputBox, StopTime,,%stoptxt%,,400,160 Loop, parse, stoptime, `:`. { ; send %A_Index% is %A_LoopField% `n ;is trace for parse if A_Index = 1 stophr := A_LoopField if A_Index = 2 stopmin := A_LoopField if A_Index = 3 stopsec := A_LoopField } ;now check the data for validity if ((stophr >= 0) and (stophr <= 23) ;hour must be between 0 and 23 and (stopmin >= 0) and (stopmin <= 59) ;minute must be between 0 and 59 and (stopsec >= 0) and (stopsec <= 59)) ;second must be between 0 and 59 { break } else { InputBox, response,,%stoptime% for STOP is invalid.`n Input Q to Quit otherwise try again } ; didn't quit so loop will try again to get the STOP time if (response = "Q") { exitapp ;quit the pgm if a Q given else return and reenter data } } ;*** End of the START/STOP times input MsgBox, ( The START time will be %starthr%:%startmin%:%startsec% The STOP time will be %stophr%:%stopmin%:%stopsec% *** Hit CTRL-Q to quit running program *** Hit ENTER or "OK" and OBS will be launched ) ; Now start OBS and pickup the PID run, %obspgm% , %OBSpath% ,,obspid ;this picks up a valid PID ; start the timing loop waiting for time matches loop, 172800 ;EXIT after 24 hours { if (startsec = A_sec) and (startmin = A_min) and (starthr = A_hour) { WinActivate, ahk_pid %obspid% ;******************************** send {PgUp} ;**** ;******************************** break } sleep, 500 ;keep testing every 1/2 second for time trigger } ; now we're in a recording mode so wait for stop time loop, 172800 ;EXIT after 24 hours { if (stopsec = A_sec) and (stopmin = A_min) and (stophr = A_hour) { WinActivate, ahk_pid %obspid% ;******************************** send {PgDn} ;**** ;******************************** break } sleep, 500 ;keep testing every 1/2 second for time trigger } ; ******************** MsgBox, Successfully completed a START/STOP recording cycle exitapp ;******************** ^q:: msgbox, 4096,,OBS timed recording CANCELLED exitapp ; provide a way to kill this running AutoHotkey OBSclkRecXtrol.ahk return