forked from shanselman/PowerPointToOBSSceneSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
70 lines (63 loc) · 2.28 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Office.Interop.PowerPoint;
//Thanks to CSharpFritz and EngstromJimmy for their gists, snippets, and thoughts.
namespace PowerPointToOBSSceneSwitcher
{
class Program
{
private static Application ppt = new Microsoft.Office.Interop.PowerPoint.Application();
private static ObsLocal OBS;
static async Task Main(string[] args)
{
Console.Write("Connecting to PowerPoint...");
ppt.SlideShowNextSlide += App_SlideShowNextSlide;
Console.WriteLine("connected");
Console.Write("Connecting to OBS...");
OBS = new ObsLocal();
await OBS.Connect();
Console.WriteLine("connected");
Console.ReadLine();
}
async static void App_SlideShowNextSlide(SlideShowWindow Wn)
{
if (Wn != null)
{
Console.WriteLine($"Moved to Slide Number {Wn.View.Slide.SlideNumber}");
//Text starts at Index 2 ¯\_(ツ)_/¯
var note = String.Empty;
try { note = Wn.View.Slide.NotesPage.Shapes[2].TextFrame.TextRange.Text; }
catch { /*no notes*/ }
var notereader = new StringReader(note);
string line;
while ((line = notereader.ReadLine()) != null)
{
if (line.StartsWith("OBS:")) {
line = line.Substring(4).Trim();
await HandleCommand(line);
}
}
}
}
static async Task HandleCommand(string command)
{
switch (command)
{
case "":
break;
case "**START":
OBS.StartRecording();
break;
case "**STOP":
OBS.StopRecording();
break;
default:
Console.WriteLine($" Switching to OBS Scene named \"{command}\"");
try { OBS.ChangeScene(command); }
catch (Exception ex) { Console.WriteLine($" ERROR: {ex.Message.ToString()}"); }
break;
}
}
}
}