feat: switching slides

This commit is contained in:
Gerard Gascón 2024-06-07 00:08:43 +02:00
parent 0ebb7f6459
commit 0705fe3adc
3 changed files with 42 additions and 0 deletions

View file

@ -2,7 +2,9 @@
class Program { class Program {
private static async Task Main() { private static async Task Main() {
GamepadReader reader = new JoyConRead(); GamepadReader reader = new JoyConRead();
SlideSwitcher switcher = new(reader);
await reader.Read(); await reader.Read();
switcher.Dispose();
} }
} }
} }

26
SlideSwitcher.cs Normal file
View file

@ -0,0 +1,26 @@
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);
}
}

14
Win32Api.cs Normal file
View file

@ -0,0 +1,14 @@
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();
}