From 4aaedac17c0a791fad69c3597c7acff404d6265e Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Fri, 3 Jan 2025 20:02:27 +0100 Subject: [PATCH] Implement wrap around for the damn 0 (should be 123..90 not 0123..9) --- DD2Switcher/Program.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/DD2Switcher/Program.cs b/DD2Switcher/Program.cs index fed682b..1d2d8ec 100644 --- a/DD2Switcher/Program.cs +++ b/DD2Switcher/Program.cs @@ -136,6 +136,9 @@ internal static class Program { } private static void Swap(int index) { + index = (index - 1) % NumProc; + if (index < 0) index = NumProc - 1; + if (index >= NumProc) return; Console.WriteLine($"Swapping window at index {index}"); var process = GetForegroundProcess(); if (process == null) return; @@ -172,6 +175,8 @@ internal static class Program { } private static void TabTo(int index) { + index = (index - 1) % NumProc; + if (index < 0) index = NumProc - 1; if (index >= NumProc) return; Console.WriteLine($"Tab to window at index {index}"); @@ -203,8 +208,8 @@ internal static class Program { for (int i = 0; i < NumProc; i++) { windows[i] = null; - HotKeyManager.RegisterHotKey(Keys.D1 + i, KeyModifiers.Alt); - HotKeyManager.RegisterHotKey(Keys.D1 + i, KeyModifiers.Alt | KeyModifiers.Shift); + HotKeyManager.RegisterHotKey(Keys.D0 + i, KeyModifiers.Alt); + HotKeyManager.RegisterHotKey(Keys.D0 + i, KeyModifiers.Alt | KeyModifiers.Shift); } HotKeyManager.RegisterHotKey(Keys.Oemtilde, KeyModifiers.Alt); @@ -217,10 +222,10 @@ internal static class Program { } if (e.Modifiers == KeyModifiers.Alt) { - TabTo(e.Key - Keys.D1); + TabTo(e.Key - Keys.D0); } else if (e.Modifiers == (KeyModifiers.Alt | KeyModifiers.Shift)) { - Swap(e.Key - Keys.D1); + Swap(e.Key - Keys.D0); } }