Jump to content

do x if script is already running


Recommended Posts

Hey,

I already wrote this "script" (lel) to have an instant "record the next 15 minutes"-button:
ControlSend ( "OBS 21.1.0 (64bit, windows) - Profil: Unbenannt - Szenen: Unbenannt", "", "[CLASS:Qt5QWindowIcon; INSTANCE:1]", "+{f12}" )      start recording
Sleep(900000)
ControlSend ( "OBS 21.1.0 (64bit, windows) - Profil: Unbenannt - Szenen: Unbenannt", "", "[CLASS:Qt5QWindowIcon; INSTANCE:1]", "+{f11}" )      stop recording after 15 minutes
 

the problem is: if eg 10 minutes passed after starting the recording and I wanted to extend the recording for another 15 minutes by using this script the script would still stop the recording after the 5 remaining minutes instead of 15.

I don't understand how to set up "if script is already running, cancel that script". i've read a forum post that said you should use something with _singleton for this but I didn't understand how to use it. Can someone maybe write a blanko for me or give me a better explanation for it?

Appreciating your help,

 

eliass123

Edited by eliass123
Link to comment
Share on other sites

  • 1 month later...
On 12.4.2018 at 7:36 PM, Danp2 said:

I would suggest modifying your current script so that you could just hit a hotkey to extend the delay time.  You would need to get rid of the Sleep command and replace it with a loop. Take a look at the help file examples for _Timer_SetTimer and _WinAPI_SetTimer.

sorry for the late answer

the pages of the functions you mentioned look very confusing and complicated to me. I'd appreciate if any of you guys would make me a blanko instead. I also couldn't find any better explanations on google/youtube

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

2 hours ago, ViciousXUSMC said:

;ControlSend ( "OBS 21.1.0 (64bit, windows) - Profil: Unbenannt - Szenen: Unbenannt", "", "[CLASS:Qt5QWindowIcon; INSTANCE:1]", "+{f12}" )      start recording

thank you for your effort

I have to remove the " ; " before the "ControlSend" otherwise the key command isn't actually sent to obs (so the recording wouldn't start).

The problem now is that the script doesn't run continuously in the background at all (although it sends "+{f12}" to obs correctly)

Instead, I get this error message on start image.thumb.png.eb719d0170306b9aa350b3d3db021460.png.

Also, how do you extend the time without entering something into an inputbox? I'd like to extend the time by a set amount just via 1 hotkey.

Edited by eliass123
Link to comment
Share on other sites

The phrase "start recording" came from your first post. This is causing a problem because it isn't valid Autoit syntax. The assumption is that you meant this to be a comment for that line. Therefore, you should add a semi-colon, like this --

ControlSend ( "OBS 21.1.0 (64bit, windows) - Profil: Unbenannt - Szenen: Unbenannt", "", "[CLASS:Qt5QWindowIcon; INSTANCE:1]", "+{f12}" ) ; start recording

:yawn:

Link to comment
Share on other sites

my current version of the script is

AdlibRegister("_StopRecord", 1000*60*15)
HotKeySet("+{f6}", "_ExtendTime")                                                                                                                      

ControlSend ( "OBS 21.1.0 (64bit, windows) - Profil: Unbenannt - Szenen: Unbenannt", "", "[CLASS:Qt5QWindowIcon; INSTANCE:1]", "+{f12}" )      ;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 = 15                             ;stop recording after 15 minutes
    AdlibRegister("_StopRecord", 1000*60*$iTime)  ;x1000x60 because from miliseconds to minutes
 EndFunc

just removed the messageboxes, added a fixed value instead of the inputbox (i decyphered that shit) even though I didn't find an explanation for how to use $iTime online and I removed the semicolons (bugfixer Ph.D), everything works fine so far

Now I want to add a new feature. The feature should be activated when I start the script but not while the script is already running. 
(The feature is called replay puffer and allows you to save replays. It runs the whole time on your ram and only remembers the last eg 5 minutes of what you were doing. Then you press a hotkey and the 5 minute clip is saved on your hard drive)

ControlSend ( "OBS 21.1.0 (64bit, windows) - Profil: Unbenannt - Szenen: Unbenannt", "", "[CLASS:Qt5QWindowIcon; INSTANCE:1]", "+{f6}" )  
;save replay ;wanna use the same hotkey for everything

AdlibRegister("_StopRecord", 1000*60*15)

HotKeySet("+{f6}", "_ExtendTime")
;wanna use the same hotkey for everything



The problem is that I want to use the same hotkey to start the entire script (including the feature) as well as to extend the time.
(This means that every time I wanted to extend the time a 5 minute clip that I am already recording or have recorded via the regular method already will be saved on my hard drive unnecessarily)

A solution I thought of would be that as soon as I press a button to activate the entire script the buttons' hotkey would turn into a different one which I could set up to extend the time, although I don't know how to do this

Any suggestions?

greetings

 

 

Edited by eliass123
Link to comment
Share on other sites

$iTime is just a variable, thus why you did not find any documentation on it.

You did not fix any bugs in the code, it was pretty much written for you and had a bow put on it.

You can re-configure a hotkey by having a new hotkey designation inside the function you fire off with the first hotkey function.

 

This time I won't write it for you :)

Link to comment
Share on other sites

4 minutes ago, ViciousXUSMC said:

$iTime is just a variable, thus why you did not find any documentation on it.

You did not fix any bugs in the code, it was pretty much written for you and had a bow put on it.

You can re-configure a hotkey by having a new hotkey designation inside the function you fire off with the first hotkey function.

 

This time I won't write it for you :)

but what is the name of the function that allows me to do that? (edit: HotKeySet, right?)

well I was just joking cause that's kinda how it felt to me since I'm a beginner

 

Edited by eliass123
Link to comment
Share on other sites

 

dont know how to do it im just stuck in loops. Also, I can't use a keyboard shortcut to start the script the first time. I can only open the script.exe via a keyboard button. I think otherwise it would be easier

Either it's not possible with only hotkeyset or I don't get it

i might need something like "if that window is already running" but that would be something with singleton and I didnt get how to use that one as well

t i just tried like 5 or 6 versions of it so at some point it got messy and I used another file. my main problem is that I have to set the save replay hotkey as well as send it every time I start the script but even if I set a new hotkey for that in the func _ExtendTime() it would still change the hotkey back every time I used my only button to run the script

or with more general words: (btw im not english so i have communication problems anyway)

I don't know how to make a script that changes its function the second time you activate it while only using one single button the whole time that only has the function to activate the script itself.

Edited by eliass123
Link to comment
Share on other sites

Spoiler

 

Send ("+{f5}") ; I need this for the script to trigger _ExtendTime when I press it the second time.

HotKeySet("+{f7}", "_replay") ;
Send ("+{f7}")                ;this is what I only want the first time. It saves the replay.

AdlibRegister("_StopRecord", 1000*60*15)
HotKeySet("+{f5}", "_ExtendTime")

ControlSend ( "OBS 21.1.0 (64bit, windows) - Profil: Unbenannt - Szenen: Unbenannt", "", "[CLASS:Qt5QWindowIcon; INSTANCE:1]", "+{f12}" )      ;start recording


While 1
    Sleep(10)
WEnd

Func _StopRecord()
    ;I thought about HotkeySet("something other than +{f7}", "_replay") but the HotKeySet("+{f7}", "_replay")+Send ("+{f7}") would always overwrite it
    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 = 15                              ;stop recording after 15 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

 

 

managed to do it using "Exit". forgot about that
 

ControlSend ( "OBS 21.1.0 (64bit, windows) - Profil: Unbenannt - Szenen: Unbenannt", "", "[CLASS:Qt5QWindowIcon; INSTANCE:1]", "+{f12}" )      ;start recording
Sleep(10)
Send ("+{f5}") ; I need this for the script to trigger _ExtendTime when I press it the second time.
Sleep(10)
HotKeySet("+{f3}", "_replay") ;
Sleep(10)
Send ("+{f3}")                ;this is what I only want the first time. It saves the replay.
Sleep(10)
AdlibRegister("_StopRecord", 1000*60*15)
Sleep(10)
;hierhin exit?

While 1
    Sleep(10)
WEnd

Func _StopRecord()
   Sleep(10)
    ControlSend ( "OBS 21.1.0 (64bit, windows) - Profil: Unbenannt - Szenen: Unbenannt", "", "[CLASS:Qt5QWindowIcon; INSTANCE:1]", "+{f11}" )
    Sleep(10)
    HotKeySet("+{f5}", "_ExtendTime")
    Exit
 EndFunc

Func _ExtendTime()
   Sleep(10)
    $iTime = 3                              ;stop recording after 15 minutes
    AdlibRegister("_StopRecord", 1000*60*$iTime)
    Exit
 EndFunc

Func _replay()
   Sleep(10)
ControlSend ( "OBS 21.1.0 (64bit, windows) - Profil: Unbenannt - Szenen: Unbenannt", "", "[CLASS:Qt5QWindowIcon; INSTANCE:1]", "+{f6}" )
EndFunc

edit. still doesnt work

Edited by eliass123
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...