Loading SlidePresenter/InputSender/LinuxInputSender.cs +20 −1 Original line number Diff line number Diff line #if OS_LINUX using System.Diagnostics; namespace ControllerSlidePresenter.InputSender; public class LinuxInputSender : IInputSender { public void NextSlide() { private const string PageUp = "0xff55"; private const string PageDown = "0xff56"; public void NextSlide() { SendKeys(PageDown); } public void PreviousSlide() { SendKeys(PageUp); } private static void SendKeys(string keycode) { Process proc = new() { StartInfo = { FileName = "xdotool", Arguments = $"key {keycode}", UseShellExecute = false, RedirectStandardError = false, RedirectStandardInput = false, RedirectStandardOutput = false } }; proc.Start(); } } #endif No newline at end of file SlidePresenter/Linux.cs 0 → 100644 +55 −0 Original line number Diff line number Diff line #if OS_LINUX using System.Diagnostics; using System.Runtime.InteropServices; namespace ControllerSlidePresenter; public static class Linux { public static bool CanRun() { if (getuid() != 0) { Console.WriteLine("On Linux you need tu run as 'sudo'"); return false; } if (!IsXdoToolInstalled()) return false; return true; } private static bool IsXdoToolInstalled() { string result = RunShellCommand("which xdotool"); if (!string.IsNullOrEmpty(result)) return true; Console.WriteLine("xdotool is not installed."); return false; } private static string RunShellCommand(string command) { try { ProcessStartInfo procStartInfo = new("bash", "-c \"" + command + "\"") { RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true, }; using Process process = new(); process.StartInfo = procStartInfo; process.Start(); string result = process.StandardOutput.ReadToEnd(); process.WaitForExit(); return result.Trim(); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return string.Empty; } } [DllImport("libc")] private static extern uint getuid(); } #endif SlidePresenter/Program.cs +5 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,11 @@ namespace ControllerSlidePresenter { internal abstract class Program { private static async Task Main() { #if OS_LINUX if (!Linux.CanRun()) return; #endif IGamepadReader? reader = ControllerSelector.GetReader(); if (reader == null) { Console.WriteLine("Invalid Controller Selected."); Loading Loading
SlidePresenter/InputSender/LinuxInputSender.cs +20 −1 Original line number Diff line number Diff line #if OS_LINUX using System.Diagnostics; namespace ControllerSlidePresenter.InputSender; public class LinuxInputSender : IInputSender { public void NextSlide() { private const string PageUp = "0xff55"; private const string PageDown = "0xff56"; public void NextSlide() { SendKeys(PageDown); } public void PreviousSlide() { SendKeys(PageUp); } private static void SendKeys(string keycode) { Process proc = new() { StartInfo = { FileName = "xdotool", Arguments = $"key {keycode}", UseShellExecute = false, RedirectStandardError = false, RedirectStandardInput = false, RedirectStandardOutput = false } }; proc.Start(); } } #endif No newline at end of file
SlidePresenter/Linux.cs 0 → 100644 +55 −0 Original line number Diff line number Diff line #if OS_LINUX using System.Diagnostics; using System.Runtime.InteropServices; namespace ControllerSlidePresenter; public static class Linux { public static bool CanRun() { if (getuid() != 0) { Console.WriteLine("On Linux you need tu run as 'sudo'"); return false; } if (!IsXdoToolInstalled()) return false; return true; } private static bool IsXdoToolInstalled() { string result = RunShellCommand("which xdotool"); if (!string.IsNullOrEmpty(result)) return true; Console.WriteLine("xdotool is not installed."); return false; } private static string RunShellCommand(string command) { try { ProcessStartInfo procStartInfo = new("bash", "-c \"" + command + "\"") { RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true, }; using Process process = new(); process.StartInfo = procStartInfo; process.Start(); string result = process.StandardOutput.ReadToEnd(); process.WaitForExit(); return result.Trim(); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return string.Empty; } } [DllImport("libc")] private static extern uint getuid(); } #endif
SlidePresenter/Program.cs +5 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,11 @@ namespace ControllerSlidePresenter { internal abstract class Program { private static async Task Main() { #if OS_LINUX if (!Linux.CanRun()) return; #endif IGamepadReader? reader = ControllerSelector.GetReader(); if (reader == null) { Console.WriteLine("Invalid Controller Selected."); Loading