Loading JoyConRead.cs +3 −2 Original line number Diff line number Diff line Loading @@ -29,7 +29,6 @@ public class JoyConRead : GamepadReader { await LogDeviceInfo(joycon); joycon.ReportReceived += OnJoyConOnReportReceived; Console.WriteLine($"JoyCon ready for presenting."); joycon.StoppedOnError += (_, ex) => { Console.WriteLine(); Loading @@ -39,7 +38,9 @@ public class JoyConRead : GamepadReader { return Task.CompletedTask; }; Console.ReadKey(); Console.WriteLine("JoyCon ready for presenting."); Console.WriteLine("Press Enter to exit program."); while (Console.ReadKey().Key != ConsoleKey.Enter) { } joycon.Stop(); Console.WriteLine(); Loading Program.cs +2 −0 Original line number Diff line number Diff line Loading @@ -2,7 +2,9 @@ class Program { private static async Task Main() { GamepadReader reader = new JoyConRead(); SlideSwitcher switcher = new(reader); await reader.Read(); switcher.Dispose(); } } } No newline at end of file SlideSwitcher.cs 0 → 100644 +26 −0 Original line number Diff line number Diff line namespace SwitchSlidePresenter; public class SlideSwitcher : IDisposable { private readonly GamepadReader _reader; public SlideSwitcher(GamepadReader reader) { _reader = reader; _reader.NextSlide += NextSlide; _reader.PrevSlide += PreviousSlide; } public void Dispose() { _reader.NextSlide -= NextSlide; _reader.PrevSlide -= PreviousSlide; } private void NextSlide() { IntPtr handle = Win32Api.GetForegroundWindow(); Win32Api.PostMessage(handle, Win32Api.WM_KEYDOWN, Win32Api.VK_NEXT, 0); } private void PreviousSlide() { IntPtr handle = Win32Api.GetForegroundWindow(); Win32Api.PostMessage(handle, Win32Api.WM_KEYDOWN, Win32Api.VK_PRIOR, 0); } } No newline at end of file Win32Api.cs 0 → 100644 +14 −0 Original line number Diff line number Diff line using System.Runtime.InteropServices; namespace SwitchSlidePresenter; public static class Win32Api { public const UInt32 WM_KEYDOWN = 0x0100; public const int VK_NEXT = 0x22; public const int VK_PRIOR = 0x21; [DllImport("user32.dll")] public static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam); [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); } No newline at end of file Loading
JoyConRead.cs +3 −2 Original line number Diff line number Diff line Loading @@ -29,7 +29,6 @@ public class JoyConRead : GamepadReader { await LogDeviceInfo(joycon); joycon.ReportReceived += OnJoyConOnReportReceived; Console.WriteLine($"JoyCon ready for presenting."); joycon.StoppedOnError += (_, ex) => { Console.WriteLine(); Loading @@ -39,7 +38,9 @@ public class JoyConRead : GamepadReader { return Task.CompletedTask; }; Console.ReadKey(); Console.WriteLine("JoyCon ready for presenting."); Console.WriteLine("Press Enter to exit program."); while (Console.ReadKey().Key != ConsoleKey.Enter) { } joycon.Stop(); Console.WriteLine(); Loading
Program.cs +2 −0 Original line number Diff line number Diff line Loading @@ -2,7 +2,9 @@ class Program { private static async Task Main() { GamepadReader reader = new JoyConRead(); SlideSwitcher switcher = new(reader); await reader.Read(); switcher.Dispose(); } } } No newline at end of file
SlideSwitcher.cs 0 → 100644 +26 −0 Original line number Diff line number Diff line namespace SwitchSlidePresenter; public class SlideSwitcher : IDisposable { private readonly GamepadReader _reader; public SlideSwitcher(GamepadReader reader) { _reader = reader; _reader.NextSlide += NextSlide; _reader.PrevSlide += PreviousSlide; } public void Dispose() { _reader.NextSlide -= NextSlide; _reader.PrevSlide -= PreviousSlide; } private void NextSlide() { IntPtr handle = Win32Api.GetForegroundWindow(); Win32Api.PostMessage(handle, Win32Api.WM_KEYDOWN, Win32Api.VK_NEXT, 0); } private void PreviousSlide() { IntPtr handle = Win32Api.GetForegroundWindow(); Win32Api.PostMessage(handle, Win32Api.WM_KEYDOWN, Win32Api.VK_PRIOR, 0); } } No newline at end of file
Win32Api.cs 0 → 100644 +14 −0 Original line number Diff line number Diff line using System.Runtime.InteropServices; namespace SwitchSlidePresenter; public static class Win32Api { public const UInt32 WM_KEYDOWN = 0x0100; public const int VK_NEXT = 0x22; public const int VK_PRIOR = 0x21; [DllImport("user32.dll")] public static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam); [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); } No newline at end of file