PowerPoint VBA 'SendKeys' no longer working
Opened this issue · 2 comments
Operating System Info
Windows 11
Other OS
No response
OBS Studio Version
31.1.2
OBS Studio Version (Other)
No response
OBS Studio Log URL
https://obsproject.com/logs/EZqXX8QN2oDvtmfP
OBS Studio Crash Log URL
No response
Expected Behavior
For a number of years I have used Microsoft Visual Basic for Applications in PowerPoint to control OBS Studio, i.e. a change of slide in PowerPoint uses 'SendKeys' to mimic a hotkey in OBS Studio and switch to a different scene. This worked up to OBS version 30.2.3 but sometime after that an update broke this functionality and newer versions of OBS no longer respond to the 'SendKeys' instruction. I'm not sure which version update broke this functionality but it basically means I am stuck at version 30.2.3 until the issue can be resolved. (Attached log file is of this working with version 30.2.3)
Current Behavior
PowerPoint 'SendKeys' didn't work to trigger the hotkeys. (Attached log file is of this not working with version 31.1.2 - uses the same powerpoint slideshow as above)
Steps to Reproduce
- when triggered by particular slide changes Powerpoint uses VB to switch focus to OBS (this works)
- a SendKeys hotkey is sent to switch scenes in OBS (this is broken in versions after 30.2.3)
- The VB script shifts focus back to the Powerpoint slideshow (this works)
...
Anything else we should know?
Here's the VB I'm using:
#If Win64 Then
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#Else
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
Private Declare PtrSafe Function WaitMessage Lib "user32" () As Long
Option Base 1
Const offering As Integer = 15 'populate with offering slide number
Const catechism As Integer = 99 'populate with catechism slide number (or 99 if no catechism)
Const covenantstart As Integer = 99 'populate with first covenant slide number (or 99 if no covenant)
Const covenantend As Integer = 99 'populate with last covenant slide number (or 99 if no covenant)
Const finalslide As Integer = 76 'populate with the last visible slide number
Dim songstart(6) As Integer
Dim songend(6) As Integer
Sub AssignSongs()
songstart(1) = 4 'populate with first slide number of each song (DUPLICATE FIRST SLIDE in PP)
songend(1) = 6 'populate with the last slide number of each song
songstart(2) = 10
songend(2) = 13
songstart(3) = 28
songend(3) = 30
songstart(4) = 37
songend(4) = 41
songstart(5) = 57
songend(5) = 64
songstart(6) = 67
songend(6) = 73
End Sub
Sub initiatePP()
ShowOBSisListening
ActivePresentation.SlideShowWindow.View.Next
ShowCamera
PauseProcess 5
ShowPP
AssignSongs
End Sub
Sub OnSlideShowPageChange()
Dim currentSlide As Integer
currentSlide = ActivePresentation.SlideShowWindow.View.CurrentShowPosition
If currentSlide = 3 Then
ShowCamera
StartStream
PauseProcess
StartStream
Exit Sub
ElseIf currentSlide = offering Then
ShowPPoffering
Exit Sub
ElseIf currentSlide = catechism Then
ShowPPcatechism
Exit Sub
ElseIf (currentSlide = offering + 1) Or (currentSlide = catechism + 1) Then
ShowCamera
Exit Sub
ElseIf currentSlide = finalslide Then
ShowOutro
Exit Sub
ElseIf currentSlide = covenantstart Then
ShowPPintro
Exit Sub
ElseIf currentSlide = covenantend + 1 Then
ShowCamera
Exit Sub
End If
Dim songnumber As Integer
For songnumber = 1 To 6
If currentSlide = songstart(songnumber) Then
ShowPPintro
Exit Sub
ElseIf currentSlide = songstart(songnumber) + 1 Then
ShowPPsong
Exit Sub
ElseIf currentSlide = songend(3) + 1 Then
ReadySermon
Exit Sub
ElseIf currentSlide = songend(songnumber) + 1 Then
ShowCamera
Exit Sub
End If
Next songnumber
End Sub
Sub ShowPP()
AppActivate "OBS"
PauseProcess
SendKeys "^{6}"
PauseProcess
AppActivate "PowerPoint Slide Show"
End Sub
Sub ShowPPintro()
AppActivate "OBS"
PauseProcess
SendKeys "^{2}"
PauseProcess
AppActivate "PowerPoint Slide Show"
End Sub
Sub ShowPPsong()
AppActivate "OBS"
PauseProcess
SendKeys "^{3}"
PauseProcess
AppActivate "PowerPoint Slide Show"
End Sub
Sub ShowPPoffering()
AppActivate "OBS"
PauseProcess
SendKeys "^{4}"
PauseProcess
AppActivate "PowerPoint Slide Show"
End Sub
Sub ShowPPcatechism()
AppActivate "OBS"
PauseProcess
SendKeys "^{5}"
PauseProcess
AppActivate "PowerPoint Slide Show"
End Sub
Sub ShowCamera()
AppActivate "OBS"
PauseProcess
SendKeys "^{1}"
PauseProcess
AppActivate "PowerPoint Slide Show"
End Sub
Sub ReadySermon()
AppActivate "OBS"
PauseProcess
SendKeys "^{0}"
PauseProcess
AppActivate "PowerPoint Slide Show"
End Sub
Sub ShowOutro()
AppActivate "OBS"
PauseProcess
SendKeys "^{7}"
PauseProcess
AppActivate "PowerPoint Slide Show"
End Sub
Sub StartStream()
AppActivate "OBS"
PauseProcess
SendKeys "+{RIGHT}"
PauseProcess 1
SendKeys "+{RIGHT}"
PauseProcess 2
AppActivate "PowerPoint Slide Show"
End Sub
Sub ShowOBSisListening()
AppActivate "OBS"
PauseProcess
AppActivate "PowerPoint Slide Show"
End Sub
Sub PauseProcess(Optional pausetime)
If IsMissing(pausetime) Then
pausetime = 0.1
End If
Sleep pausetime * 1000
End Sub
I cannot reproduce the issue on OBS Studio 31.1.2.
Based on your code, because you are raising the window, I assume you set "Disable hotkeys when main window is not in focus". Using this VBA code on PowerPoint, the action assigned to the hotkey Ctrl+1 works.
AppActivate "OBS"
Sleep 100
SendKeys "^{1}"
As a footnote, I don't recommend using the hotkeys to communicate between programs like this. OBS Studio provides websocket interface, which is the more robust way, in my opinion.
Thanks for your response norihiro.
After a great deal of trial and error I discovered where the problem lies. OBS used to accept arrow keys as hotkeys, e.g.:
SendKeys "^{RIGHT}"
SendKeys "+{RIGHT}"
Both the above used to work (still do with version 30.2.3), and using the physical keyboard the arrows can still be used as hotkeys in OBS, but OBS no longer accepts them from VB SendKeys. Futhermore, OBS will no longer accept ANY SendKeys after you attempt using the above examples. So in my script, the first couple of SendKey commands worked, but after I attempted to start the stream or recording (using the RIGHT arrow SendKey) the rest of the powerpoint didn't trigger any scene changes in OBS. So basically, you can now ONLY use SendKeys with numeric values.
Regarding your footnote, I have personally found hotkeys sent from PowerPoint to be very robust: I have been using this for 4+ years without any issues until now. Hopefully OBS doesn't make changes that prevent the use of numeric hotkeys.
Thanks again for confirming that SendKeys "^{1}" was working for you: it set me on the path to resolving the issue we were having.