Automatically Switching Scenes in OBS

Get help with using AutoHotkey and its commands and hotkeys
Nupper
Posts: 2
Joined: 06 Jun 2016, 21:28

Automatically Switching Scenes in OBS

06 Jun 2016, 21:33

I am attempting to switch scenes on a loop in OBS (Open Broadcaster Software) every 60 seconds. I have bound my scenes to F11 and F10. I am VERY new to AHK so bare with me.

I wrote a very simple script attempting to send the key strokes.

Code: Select all

Loop {
Sleep, 60000
Send, {F11}
Sleep, 60000
Send, {F12}
}
The problem is that it doesn't always send this to my OBS window or the OBS window doesn't recognize it. For some reason it only works sometimes. I am not sure what the issue is.

Thank you for your help!
User avatar
Masonjar13
Posts: 1459
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: Automatically Switching Scenes in OBS

06 Jun 2016, 21:47

Try ControlSend. It will always send it to the specified window. Whether the window will accept it or not is something else.

Code: Select all

loop {
    sleep 60000
    controlSend,,{F11},ahk_class Qt5QWindowIcon ; This class name is for OBS Studio. If you're using the other version, you can get the class name with AU3_Spy, application included with AHK.
    sleep 60000
    controlSend,,{F12},ahk_class Qt5QWindowIcon
}
Your syntax was fine by the way.
OS: Windows 7 Ultimate | Editor: Notepad++
My Personal Function Library | Check Out My Computer Rig
Nupper
Posts: 2
Joined: 06 Jun 2016, 21:28

Re: Automatically Switching Scenes in OBS

06 Jun 2016, 22:40

I really appreciate your help. That seemed to work out for me perfectly. I should have come to the forums first! Thank you so much!
homezonebenny
Posts: 18
Joined: 23 Apr 2016, 08:36

Re: Automatically Switching Scenes in OBS

20 May 2017, 22:07

Hi,
I know that's a bit older post. But I use this:

Code: Select all

#o::
controlSend,, ^!{Numpad3},ahk_class Qt5QWindowIcon
return
Just for testing switching the OBS scene.
I have a much longer scene switcher script.
But it wont switch my OBS scenes.

I set them to:
CTRL + ALT + NUM 0 up to 9

So I tested it with Numpad3.
When I use this method it only works sometimes. When I spam that Windows + O key hard...
I just use the Windows + O for testing the send command.

Since:
Send ^!{Numpad3}
is just not working with OBS Scene switcher. I really don't know what to do.

Any other solution then the Qt5 thing?!

EDIT:
It's working 100% when I HOLD down Windows key AND hold down the O letter...
After ~2-3 sec (it spam the hotkey.......) it switch the scene.
This is totally not good. Since my script will only press it ONE time.
User avatar
Masonjar13
Posts: 1459
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: Automatically Switching Scenes in OBS

21 May 2017, 04:14

Code: Select all

$#o::
send {lwin up}{rwin up}
controlSend,, ^!{Numpad3},ahk_class Qt5QWindowIcon
return
The win-key often has problems when using it in this way. Because of the problem you're having, I can only assume that the win-key modifies the controlSend keys, or OBS at least picks up on it, meaning it's very likely not being sent correctly to the window. By 'forcing' the win-keys to be 'up', it won't modify the controlSend keys, because it won't be perceived as pressed by the system, even if you're physically pressing it. I added the hook-prefix just to make sure.

To clarify, Qt is a cross-platform GUI framework. OBS Studio is cross-platform and decided to use Qt, so Qt5QWindowIcon is the class name of the window, an identifier (whether you can change this or not, I'm unaware). In your case, it has nothing to do with the controlSend not working; if the class no longer matched, you'd have a 100% failure rate using any hotkey.
OS: Windows 7 Ultimate | Editor: Notepad++
My Personal Function Library | Check Out My Computer Rig
homezonebenny
Posts: 18
Joined: 23 Apr 2016, 08:36

Re: Automatically Switching Scenes in OBS

22 May 2017, 03:56

But it's the same with:

Code: Select all

!6::
{
  controlSend,,^!{Numpad3}, ahk_class Qt5QWindowIcon
  return
}
And the win key is not in it.
I'll try it that way.

I'm using a complete automatic scene switcher AHK script.
And it only works when I put the controlSend 3x in it...
So it works 100% of time. with 2x it works only 95% of time... with 1x only like 30% of time...


EDIT:
I tested:
send {lwin up}{rwin up}
And it's not working. Have to spam the O letter a lot. Like holding Win key down, and spamming O until it works.
At the moment the only way is:

Code: Select all

#o::
{
controlSend,,^!{Numpad3}, ahk_class Qt5QWindowIcon
controlSend,,^!{Numpad3}, ahk_class Qt5QWindowIcon
controlSend,,^!{Numpad3}, ahk_class Qt5QWindowIcon
return
}
This makes it instantly and work 100% of time. :\

Interessting is, that this is working 100% of time:

Code: Select all

^!6::
{
  controlSend,,^!{Numpad3}, ahk_class Qt5QWindowIcon
  return
}
But with
!6::
not. I don't know... just strange.
The 3x controlSend works. So it's fine. And it's not harmful to obs scene switching, pressing a hotkey 3 times.
Like flickering scene or something. It just don't feel right at all.


My other posts about it are:
https://autohotkey.com/boards/viewtopic ... 18&t=31614
and
https://autohotkey.com/boards/viewtopic.php?f=5&t=32041
User avatar
jeeswg
Posts: 6394
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Automatically Switching Scenes in OBS

22 May 2017, 11:33

If a hotkey has ! (Alt) in it, then maybe {Alt Up} or {LAlt Up} would be useful.

Acc can be used to invoke buttons in OBS Studio, via accDoDefaultAction, if that's of any use:

obs studio start and record - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=26124
OBS Studio Scenes - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=28345
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
roninpawn
Posts: 1
Joined: 14 Jun 2019, 12:14
GitHub: roninpawn

Re: Automatically Switching Scenes in OBS

14 Jun 2019, 12:21

I think I've figured this OBS/AHK hotkey thing out.

There are two things that ControlSend screws up with OBS. (or that OBS handles poorly from AHK, depending how you want to look at it.) The first is that AHK sends a CTRL key in front of a modifier key, and sometimes OBS reads the CTRL key and doesn't get the rest of it. See here for details:
https://www.autohotkey.com/docs/commands/_MenuMaskKey.htm

The second is that the default timing of the ControlSend event is too quick for OBS to recognize. So sometimes, if you're sending ALT+Numpad4, all OBS gets is the ALT.
You can see what OBS is actually receiving by going to OBS's hotkey setup page and pressing your AHK hotkey while setting one of the fields.

So here's the code that fixed it for me:

Code: Select all

#MenuMaskKey vk07  ;Takes the extra CTRL event out of Alt+ hotkeys.
SetKeyDelay, -1, 50  ;Simulates holding down the key for 50ms.
*!Numpad4::ControlSend, , !{Numpad4}, ahk_class Qt5QWindowIcon  ;Sends Alt+Numpad4 when... alt+numpad4 is pressed. I have my reasons!
I searched and searched and found tons of people having this issue along with me... No one with an explanation or solution. Hopefully this post will put the nail in the coffin on why OBS sometimes fails to hear hotkeys from AutoHotKey scripts.
Adabriel
Posts: 2
Joined: 14 Jun 2019, 18:14

Re: Automatically Switching Scenes in OBS

14 Jun 2019, 18:20

loop {
sleep 3000
controlSend,,{F5},ahk_class Qt5QWindowIcon
sleep 3000
controlSend,,{F6},ahk_class Qt5QWindowIcon
sleep 3000
controlSend,,{F7},ahk_class Qt5QWindowIcon
}

Break::
Pause,Toggle
Return

So this worked for a number of days (albeit the sleep timer was set for 10 mins = 600000ms for each 'delay'), but as of today this has not worked today. Not trying to hijack thread, but after seeing Masonjar13's solution (plus the toggle pause hotkey addition) I don't understand how it was working a week ago, but now its failing to be picked up by OBS - have run script, and know the Pause/Break Key to Pause the script works, but nothing is being picked up by OBS.

And yes, I have checked to ensure the Hotkeys in OBS are allocated correctly and saved.
Adabriel
Posts: 2
Joined: 14 Jun 2019, 18:14

Re: Automatically Switching Scenes in OBS

14 Jun 2019, 20:05

Nvm figured out the error:

Loop,
{
ControlSend,,{F5},ahk_class Qt5QWindowIcon
Sleep 5000
ControlSend,,{F6},ahk_class Qt5QWindowIcon
Sleep 5000
ControlSend,,{F7},ahk_class Qt5QWindowIcon
Sleep 5000
}

Break::
Pause,Toggle
Return

It must've been the way I didn't set the comma after 'Loop', hope this helps

Return to “Ask For Help”

Who is online

Users browsing this forum: Albireo, cadudesun, DMDComposer, Flipeador, kostons, Rohwedder, Samantha and 187 guests