diff --git a/DD2Switcher/App.config b/DD2Switcher/App.config
index 69f9d64..8a99d30 100644
--- a/DD2Switcher/App.config
+++ b/DD2Switcher/App.config
@@ -1,6 +1,6 @@
-
+
-
+
-
\ No newline at end of file
+
diff --git a/DD2Switcher/DD2Switcher.csproj b/DD2Switcher/DD2Switcher.csproj
index 397cbea..35acb00 100644
--- a/DD2Switcher/DD2Switcher.csproj
+++ b/DD2Switcher/DD2Switcher.csproj
@@ -1,87 +1,88 @@
-
-
- Debug
- AnyCPU
- {2AC26899-8E27-4B96-85A9-C387186EAD27}
- WinExe
- DD2Switcher
- DD2Switcher
- v4.8.1
- 512
- true
- true
- 9.0
-
-
- x64
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
- false
-
-
- x64
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Form
-
-
- Form1.cs
-
-
-
-
-
- ResXFileCodeGenerator
- Resources.Designer.cs
- Designer
-
-
- True
- Resources.resx
-
-
- SettingsSingleFileGenerator
- Settings.Designer.cs
-
-
- True
- Settings.settings
- True
-
-
-
-
-
-
-
-
-
+
+
+ Debug
+ AnyCPU
+ {2AC26899-8E27-4B96-85A9-C387186EAD27}
+ WinExe
+ DD2Switcher
+ DD2Switcher
+ v4.8
+ 512
+ true
+ true
+ 9.0
+
+
+
+ x64
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+ false
+
+
+ x64
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Form
+
+
+ Form1.cs
+
+
+
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+ Designer
+
+
+ True
+ Resources.resx
+
+
+ SettingsSingleFileGenerator
+ Settings.Designer.cs
+
+
+ True
+ Settings.settings
+ True
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/DD2Switcher/Form1.Designer.cs b/DD2Switcher/Form1.Designer.cs
index 6d11d59..e327d81 100644
--- a/DD2Switcher/Form1.Designer.cs
+++ b/DD2Switcher/Form1.Designer.cs
@@ -1,36 +1,36 @@
namespace DD2Switcher {
-partial class Form1 {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
+ partial class Form1 {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed;
- /// otherwise, false.
- protected override void Dispose(bool disposing) {
- if (disposing && (components != null)) {
- components.Dispose();
- }
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed;
+ /// otherwise, false.
+ protected override void Dispose(bool disposing) {
+ if (disposing && (components != null)) {
+ components.Dispose();
+ }
- base.Dispose(disposing);
- }
+ base.Dispose(disposing);
+ }
#region Windows Form Designer generated code
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent() {
- this.components = new System.ComponentModel.Container();
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(800, 450);
- this.Text = "Form1";
- }
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent() {
+ this.components = new System.ComponentModel.Container();
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Text = "Form1";
+ }
#endregion
-}
+ }
}
\ No newline at end of file
diff --git a/DD2Switcher/Form1.cs b/DD2Switcher/Form1.cs
index 7a6f553..4595d64 100644
--- a/DD2Switcher/Form1.cs
+++ b/DD2Switcher/Form1.cs
@@ -1,7 +1,9 @@
using System.Windows.Forms;
namespace DD2Switcher {
-public partial class Form1 : Form {
- public Form1() { InitializeComponent(); }
-}
+ public partial class Form1 : Form {
+ public Form1() {
+ InitializeComponent();
+ }
+ }
}
\ No newline at end of file
diff --git a/DD2Switcher/HotKeyManager.cs b/DD2Switcher/HotKeyManager.cs
index efa64fb..feca266 100644
--- a/DD2Switcher/HotKeyManager.cs
+++ b/DD2Switcher/HotKeyManager.cs
@@ -4,109 +4,97 @@ using System.Threading;
using System.Windows.Forms;
namespace DD2Switcher {
-public static class HotKeyManager {
- private static volatile MessageWindow _wnd;
- private static volatile IntPtr _hwnd;
- private static readonly ManualResetEvent _windowReadyEvent = new(false);
+ public static class HotKeyManager {
+ private static volatile MessageWindow _wnd;
+ private static volatile IntPtr _hwnd;
+ private static readonly ManualResetEvent _windowReadyEvent = new(false);
- private static int _id;
+ private static int _id;
- static HotKeyManager() {
- var messageLoop =
- new Thread(delegate() { Application.Run(new MessageWindow()); });
- messageLoop.Name = "MessageLoopThread";
- messageLoop.IsBackground = true;
- messageLoop.Start();
- }
+ static HotKeyManager() {
+ var messageLoop = new Thread(delegate() { Application.Run(new MessageWindow()); });
+ messageLoop.Name = "MessageLoopThread";
+ messageLoop.IsBackground = true;
+ messageLoop.Start();
+ }
- public static event EventHandler HotKeyPressed;
+ public static event EventHandler HotKeyPressed;
- public static int RegisterHotKey(Keys key, KeyModifiers modifiers) {
- _windowReadyEvent.WaitOne();
- var id = Interlocked.Increment(ref _id);
- _wnd.Invoke(new RegisterHotKeyDelegate(RegisterHotKeyInternal), _hwnd, id,
- (uint)modifiers, (uint)key);
- return id;
- }
+ public static int RegisterHotKey(Keys key, KeyModifiers modifiers) {
+ _windowReadyEvent.WaitOne();
+ var id = Interlocked.Increment(ref _id);
+ _wnd.Invoke(new RegisterHotKeyDelegate(RegisterHotKeyInternal), _hwnd, id, (uint)modifiers, (uint)key);
+ return id;
+ }
- public static void UnregisterHotKey(int id) {
- _wnd.Invoke(new UnRegisterHotKeyDelegate(UnRegisterHotKeyInternal), _hwnd,
- id);
- }
+ public static void UnregisterHotKey(int id) {
+ _wnd.Invoke(new UnRegisterHotKeyDelegate(UnRegisterHotKeyInternal), _hwnd, id);
+ }
- private static void RegisterHotKeyInternal(IntPtr hwnd, int id,
- uint modifiers, uint key) {
- RegisterHotKey(hwnd, id, modifiers, key);
- }
+ private static void RegisterHotKeyInternal(IntPtr hwnd, int id, uint modifiers, uint key) {
+ RegisterHotKey(hwnd, id, modifiers, key);
+ }
- private static void UnRegisterHotKeyInternal(IntPtr hwnd, int id) {
- UnregisterHotKey(_hwnd, id);
- }
+ private static void UnRegisterHotKeyInternal(IntPtr hwnd, int id) {
+ UnregisterHotKey(_hwnd, id);
+ }
- private static void OnHotKeyPressed(HotKeyEventArgs e) {
- if (HotKeyPressed != null)
- HotKeyPressed(null, e);
- }
+ private static void OnHotKeyPressed(HotKeyEventArgs e) {
+ if (HotKeyPressed != null)
+ HotKeyPressed(null, e);
+ }
- [DllImport("user32", SetLastError = true)]
- private static extern bool RegisterHotKey(IntPtr hWnd, int id,
- uint fsModifiers, uint vk);
+ [DllImport("user32", SetLastError = true)]
+ private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
- [DllImport("user32", SetLastError = true)]
- private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
+ [DllImport("user32", SetLastError = true)]
+ private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
- private delegate void RegisterHotKeyDelegate(IntPtr hwnd, int id,
- uint modifiers, uint key);
+ private delegate void RegisterHotKeyDelegate(IntPtr hwnd, int id, uint modifiers, uint key);
- private delegate void UnRegisterHotKeyDelegate(IntPtr hwnd, int id);
+ private delegate void UnRegisterHotKeyDelegate(IntPtr hwnd, int id);
- private class MessageWindow : Form {
- private const int WM_HOTKEY = 0x312;
+ private class MessageWindow : Form {
+ private const int WM_HOTKEY = 0x312;
- public MessageWindow() {
- _wnd = this;
- _hwnd = Handle;
- _windowReadyEvent.Set();
+ public MessageWindow() {
+ _wnd = this;
+ _hwnd = Handle;
+ _windowReadyEvent.Set();
+ }
+
+ protected override void WndProc(ref Message m) {
+ if (m.Msg == WM_HOTKEY) {
+ var e = new HotKeyEventArgs(m.LParam);
+ OnHotKeyPressed(e);
+ }
+
+ base.WndProc(ref m);
+ }
+
+ protected override void SetVisibleCore(bool value) {
+ // Ensure the window never becomes visible
+ base.SetVisibleCore(false);
+ }
+ }
}
- protected override void WndProc(ref Message m) {
- if (m.Msg == WM_HOTKEY) {
- var e = new HotKeyEventArgs(m.LParam);
- OnHotKeyPressed(e);
- }
+ public class HotKeyEventArgs : EventArgs {
+ public readonly Keys Key;
+ public readonly KeyModifiers Modifiers;
- base.WndProc(ref m);
+ public HotKeyEventArgs(Keys key, KeyModifiers modifiers) {
+ Key = key;
+ Modifiers = modifiers;
+ }
+
+ public HotKeyEventArgs(IntPtr hotKeyParam) {
+ var param = (uint)hotKeyParam.ToInt64();
+ Key = (Keys)((param & 0xffff0000) >> 16);
+ Modifiers = (KeyModifiers)(param & 0x0000ffff);
+ }
}
- protected override void SetVisibleCore(bool value) {
- // Ensure the window never becomes visible
- base.SetVisibleCore(false);
- }
- }
-}
-
-public class HotKeyEventArgs : EventArgs {
- public readonly Keys Key;
- public readonly KeyModifiers Modifiers;
-
- public HotKeyEventArgs(Keys key, KeyModifiers modifiers) {
- Key = key;
- Modifiers = modifiers;
- }
-
- public HotKeyEventArgs(IntPtr hotKeyParam) {
- var param = (uint)hotKeyParam.ToInt64();
- Key = (Keys)((param & 0xffff0000) >> 16);
- Modifiers = (KeyModifiers)(param & 0x0000ffff);
- }
-}
-
-[Flags]
-public enum KeyModifiers {
- Alt = 1,
- Control = 2,
- Shift = 4,
- Windows = 8,
- NoRepeat = 0x4000
-}
+ [Flags]
+ public enum KeyModifiers { Alt = 1, Control = 2, Shift = 4, Windows = 8, NoRepeat = 0x4000 }
}
\ No newline at end of file
diff --git a/DD2Switcher/Program.cs b/DD2Switcher/Program.cs
index cb9e605..fb6a654 100644
--- a/DD2Switcher/Program.cs
+++ b/DD2Switcher/Program.cs
@@ -6,289 +6,281 @@ using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace DD2Switcher {
-internal static class Program {
- private static int NumProc = 19;
- private static Process[] windows = new Process[NumProc];
- private static int ActiveIndex = -1;
+ internal static class Program {
+ private static int NumProc = 19;
+ private static Process[] windows = new Process[NumProc];
+ private static int ActiveIndex = -1;
- private static readonly IntPtr defaultAffinity = new(0xFF000000);
- private static readonly IntPtr fullAffinity = new(0xFFFFFFFF);
+ private static readonly IntPtr defaultAffinity = new(0xFF000000);
+ private static readonly IntPtr fullAffinity = new(0xFFFFFFFF);
- [DllImport("user32.dll")]
- public static extern IntPtr GetForegroundWindow();
+ [DllImport("user32.dll")]
+ public static extern IntPtr GetForegroundWindow();
- [DllImport("user32.dll")]
- public static extern bool SetForegroundWindow(IntPtr hWnd);
+ [DllImport("user32.dll")]
+ public static extern bool SetForegroundWindow(IntPtr hWnd);
- [DllImport("user32.dll")]
- private static extern short GetKeyState(int nVirtKey);
+ [DllImport("user32.dll")]
+ private static extern short GetKeyState(int nVirtKey);
- [DllImport("kernel32.dll", SetLastError = true)]
- [return:MarshalAs(UnmanagedType.Bool)]
- static extern bool AllocConsole();
+ [DllImport("kernel32.dll", SetLastError = true)]
+ [return:MarshalAs(UnmanagedType.Bool)]
+ static extern bool AllocConsole();
- [DllImport("user32.dll")]
- private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags,
- int dwExtraInfo);
+ [DllImport("user32.dll")]
+ private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
- private static void CleanWindows() {
- for (int i = 0; i < NumProc; i++) {
- var window = windows[i];
- if (window == null)
- continue;
- if (window.MainWindowHandle == IntPtr.Zero) {
- Console.WriteLine(
- $"Window at index {i} has no main window, removing from tracked windows");
- windows[i] = null;
- }
- }
- }
-
- private static void AdjustAffinities() {
- CleanWindows();
- for (int i = 0; i < NumProc; i++) {
- var window = windows[i];
- if (window == null)
- continue;
- if (i != ActiveIndex) {
- try {
- window.ProcessorAffinity = defaultAffinity;
- } catch (Exception e) {
- windows[i] = null;
+ private static void CleanWindows() {
+ for (int i = 0; i < NumProc; i++) {
+ var window = windows[i];
+ if (window == null)
+ continue;
+ if (window.MainWindowHandle == IntPtr.Zero) {
+ Console.WriteLine($"Window at index {i} has no main window, removing from tracked windows");
+ windows[i] = null;
+ }
+ }
}
- }
- }
- var active = windows[ActiveIndex];
- if (active != null) {
- try {
- active.ProcessorAffinity = fullAffinity;
- } catch (Exception e) {
- windows[ActiveIndex] = null;
- }
- }
- }
+ private static void AdjustAffinities() {
+ CleanWindows();
+ for (int i = 0; i < NumProc; i++) {
+ var window = windows[i];
+ if (window == null)
+ continue;
+ if (i != ActiveIndex) {
+ try {
+ window.ProcessorAffinity = defaultAffinity;
+ } catch (Exception e) {
+ windows[i] = null;
+ }
+ }
+ }
- private static void AdjustPriorities() {
- CleanWindows();
- for (int i = 0; i < NumProc; i++) {
- var window = windows[i];
- if (window == null)
- continue;
-
- if (i != ActiveIndex) {
- try {
- window.PriorityClass = ProcessPriorityClass.Idle;
- } catch (Exception e) {
- windows[i] = null;
+ var active = windows[ActiveIndex];
+ if (active != null) {
+ try {
+ active.ProcessorAffinity = fullAffinity;
+ } catch (Exception e) {
+ windows[ActiveIndex] = null;
+ }
+ }
}
- }
- }
- var active = windows[ActiveIndex];
- if (active != null) {
- try {
- active.PriorityClass = ProcessPriorityClass.High;
- } catch (Exception e) {
- windows[ActiveIndex] = null;
- }
- }
- }
+ private static void AdjustPriorities() {
+ CleanWindows();
+ for (int i = 0; i < NumProc; i++) {
+ var window = windows[i];
+ if (window == null)
+ continue;
- private static Process GetForegroundProcess() {
- var foregroundWindow = GetForegroundWindow();
- var process = Process.GetProcesses();
- Process foregroundProcess = null;
- foreach (var p in process)
- if (foregroundWindow == p.MainWindowHandle) {
- foregroundProcess = p;
- break;
- }
+ if (i != ActiveIndex) {
+ try {
+ window.PriorityClass = ProcessPriorityClass.Idle;
+ } catch (Exception e) {
+ windows[i] = null;
+ }
+ }
+ }
- if (foregroundProcess == null)
- return null;
- return foregroundProcess;
- }
+ var active = windows[ActiveIndex];
+ if (active != null) {
+ try {
+ active.PriorityClass = ProcessPriorityClass.High;
+ } catch (Exception e) {
+ windows[ActiveIndex] = null;
+ }
+ }
+ }
- private static Boolean ProcessTracked(int id) {
- for (int i = 0; i < NumProc; i++) {
- if (windows[i] != null && windows[i].Id == id) {
- return true;
- }
- }
+ private static Process GetForegroundProcess() {
+ var foregroundWindow = GetForegroundWindow();
+ var process = Process.GetProcesses();
+ Process foregroundProcess = null;
+ foreach (var p in process)
+ if (foregroundWindow == p.MainWindowHandle) {
+ foregroundProcess = p;
+ break;
+ }
- return false;
- }
+ if (foregroundProcess == null)
+ return null;
+ return foregroundProcess;
+ }
- private static void Track(Process process) {
- // First find the first null slot
- int firstNullIndex = -1;
- for (int i = 0; i < NumProc; i++) {
- if (windows[i] == null) {
- firstNullIndex = i;
- break;
- }
- }
+ private static Boolean ProcessTracked(int id) {
+ for (int i = 0; i < NumProc; i++) {
+ if (windows[i] != null && windows[i].Id == id) {
+ return true;
+ }
+ }
- if (firstNullIndex == -1) {
- Console.WriteLine("No slots available for tracking");
- return;
- }
+ return false;
+ }
- // Compact the array by shifting non-null elements to the left
- for (int i = firstNullIndex + 1; i < NumProc; i++) {
- if (windows[i] != null) {
- windows[firstNullIndex] = windows[i];
- windows[i] = null;
- firstNullIndex++;
- }
- }
+ private static void Track(Process process) {
+ // First find the first null slot
+ int firstNullIndex = -1;
+ for (int i = 0; i < NumProc; i++) {
+ if (windows[i] == null) {
+ firstNullIndex = i;
+ break;
+ }
+ }
- // Add the new process at the first null slot
- windows[firstNullIndex] = process;
- Console.WriteLine(
- $"Added {process.ProcessName} to tracked windows at index {firstNullIndex}");
- }
+ if (firstNullIndex == -1) {
+ Console.WriteLine("No slots available for tracking");
+ return;
+ }
- // private static void TrackWows() {
- // CleanWindows();
- // var processes = Process.GetProcesses().OrderBy(p => p.Id).ToList();
- // foreach (var process in processes) {
- // if (process.ProcessName == "UWow-64") {
- // Console.WriteLine($"Found UWow-64 at pid {process.Id}");
- // if (ProcessTracked(process.Id))
- // continue;
- // Track(process);
- // }
- // }
- // }
+ // Compact the array by shifting non-null elements to the left
+ for (int i = firstNullIndex + 1; i < NumProc; i++) {
+ if (windows[i] != null) {
+ windows[firstNullIndex] = windows[i];
+ windows[i] = null;
+ firstNullIndex++;
+ }
+ }
- private static void Swap(int index) {
- index = (index - 1) % NumProc;
- if (index < 0)
- index = NumProc - 1;
- if (index >= NumProc)
- return;
- CleanWindows();
- Console.WriteLine($"Swapping window at index {index}");
- var process = GetForegroundProcess();
- if (process == null)
- return;
- Console.WriteLine($"Foreground process: {process}");
- bool found = false;
+ // Add the new process at the first null slot
+ windows[firstNullIndex] = process;
+ Console.WriteLine($"Added {process.ProcessName} to tracked windows at index {firstNullIndex}");
+ }
- for (int i = 0; i < NumProc; i++) {
- var window = windows[i];
- if (window != null && window.Id == process.Id) {
- found = true;
- break;
- }
- }
+ // private static void TrackWows() {
+ // CleanWindows();
+ // var processes = Process.GetProcesses().OrderBy(p => p.Id).ToList();
+ // foreach (var process in processes) {
+ // if (process.ProcessName == "UWow-64") {
+ // Console.WriteLine($"Found UWow-64 at pid {process.Id}");
+ // if (ProcessTracked(process.Id))
+ // continue;
+ // Track(process);
+ // }
+ // }
+ // }
- if (!found) {
- for (int i = 0; i < NumProc; i++) {
- var window = windows[i];
- if (window == null) {
- Console.WriteLine(
- $"Adding foreground window to tracked at index {i}...");
- windows[i] = process;
+ private static void Swap(int index) {
+ index = (index - 1) % NumProc;
+ if (index < 0)
+ index = NumProc - 1;
+ if (index >= NumProc)
+ return;
+ CleanWindows();
+ Console.WriteLine($"Swapping window at index {index}");
+ var process = GetForegroundProcess();
+ if (process == null)
+ return;
+ Console.WriteLine($"Foreground process: {process}");
+ bool found = false;
+
+ for (int i = 0; i < NumProc; i++) {
+ var window = windows[i];
+ if (window != null && window.Id == process.Id) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ for (int i = 0; i < NumProc; i++) {
+ var window = windows[i];
+ if (window == null) {
+ Console.WriteLine($"Adding foreground window to tracked at index {i}...");
+ windows[i] = process;
break;
+ }
+ }
+ }
+
+ for (int i = 0; i < NumProc; i++) {
+ var window = windows[i];
+ if (window != null && window.Id == process.Id) {
+ windows[i] = windows[index];
+ windows[index] = window;
+ Console.WriteLine($"Swapped window at index {i} to {index}");
+ // Toggle caps lock off
+ keybd_event(0x14, 0, 0, 0); // KEYEVENTF_KEYDOWN
+ keybd_event(0x14, 0, 0x0002, 0); // KEYEVENTF_KEYUP
+ return;
+ }
+ }
}
- }
- }
- for (int i = 0; i < NumProc; i++) {
- var window = windows[i];
- if (window != null && window.Id == process.Id) {
- windows[i] = windows[index];
- windows[index] = window;
- Console.WriteLine($"Swapped window at index {i} to {index}");
- // Toggle scroll lock off
- keybd_event(0x91, 0, 0, 0); // KEYEVENTF_KEYDOWN
- keybd_event(0x91, 0, 0x0002, 0); // KEYEVENTF_KEYUP
- return;
- }
- }
- }
+ private static void TabTo(int index) {
+ index = (index - 1) % NumProc;
+ if (index < 0)
+ index = NumProc - 1;
+ if (index >= NumProc)
+ return;
+ CleanWindows();
+ Console.WriteLine($"Tab to window at index {index}");
- private static void TabTo(int index) {
- index = (index - 1) % NumProc;
- if (index < 0)
- index = NumProc - 1;
- if (index >= NumProc)
- return;
- CleanWindows();
- Console.WriteLine($"Tab to window at index {index}");
-
- var window = windows[index];
- if (window == null || window.MainWindowHandle == IntPtr.Zero) {
- Console.WriteLine(
- $"Window at index {index} does not exist, removing from tracked windows");
- windows[index] = null;
- } else {
- SetForegroundWindow(window.MainWindowHandle);
- ActiveIndex = index;
- AdjustAffinities();
- AdjustPriorities();
- }
- }
-
- private static bool IsScrollLockOn() { return (GetKeyState(0x91) & 1) == 1; }
-
- [STAThread]
- private static void Main() {
- // AllocConsole();
-
- var processes = Process.GetProcesses();
- var currentProcess = Process.GetCurrentProcess();
-
- foreach (var process in processes)
- if (process.Id != currentProcess.Id &&
- process.ProcessName == currentProcess.ProcessName) {
- process.Kill();
- Process.GetCurrentProcess().Kill();
- }
-
- HotKeyManager.RegisterHotKey(Keys.Scroll, KeyModifiers.NoRepeat);
- // Register main number keys (0-9)
- for (int i = 0; i < 10; i++)
- HotKeyManager.RegisterHotKey(Keys.D0 + i, KeyModifiers.Alt);
-
- // Register numpad keys (1-9)
- for (int i = 0; i < 9; i++)
- HotKeyManager.RegisterHotKey(Keys.NumPad1 + i, KeyModifiers.Alt);
-
- HotKeyManager.RegisterHotKey(Keys.Oemtilde, KeyModifiers.Alt);
- HotKeyManager.HotKeyPressed += HotKeyManager_HotKeyPressed;
-
- void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e) {
- // if (e.Key == Keys.Oemtilde && e.Modifiers == KeyModifiers.Alt) {
- // TrackWows();
- // return;
- // }
-
- int index;
- if (e.Key >= Keys.D0 && e.Key <= Keys.D9) {
- index = e.Key - Keys.D0;
- } else if (e.Key >= Keys.NumPad1 && e.Key <= Keys.NumPad9) {
- index = 10 + (e.Key - Keys.NumPad1);
- } else {
- return;
- }
-
- if (e.Modifiers == KeyModifiers.Alt) {
- if (IsScrollLockOn()) {
- Swap(index);
- } else {
- TabTo(index);
+ var window = windows[index];
+ if (window == null || window.MainWindowHandle == IntPtr.Zero) {
+ Console.WriteLine($"Window at index {index} does not exist, removing from tracked windows");
+ windows[index] = null;
+ } else {
+ SetForegroundWindow(window.MainWindowHandle);
+ ActiveIndex = index;
+ AdjustAffinities();
+ AdjustPriorities();
+ }
}
- }
- }
- Console.CancelKeyPress +=
- (sender, e) => { Process.GetCurrentProcess().Kill(); };
- while (true)
- System.Threading.Thread.Sleep(100000);
- }
-}
+ private static bool IsCapsLockOn() {
+ return (GetKeyState(0x14) & 1) == 1;
+ }
+
+ [STAThread]
+ private static void Main() {
+ // AllocConsole();
+
+ var processes = Process.GetProcesses();
+ var currentProcess = Process.GetCurrentProcess();
+
+ foreach (var process in processes)
+ if (process.Id != currentProcess.Id && process.ProcessName == currentProcess.ProcessName) {
+ process.Kill();
+ Process.GetCurrentProcess().Kill();
+ }
+
+ HotKeyManager.RegisterHotKey(Keys.Capital, KeyModifiers.NoRepeat);
+ // Register main number keys (0-9)
+ for (int i = 0; i < 10; i++) HotKeyManager.RegisterHotKey(Keys.D0 + i, KeyModifiers.Alt);
+
+ // Register numpad keys (1-9)
+ for (int i = 0; i < 9; i++) HotKeyManager.RegisterHotKey(Keys.NumPad1 + i, KeyModifiers.Alt);
+
+ HotKeyManager.RegisterHotKey(Keys.Oemtilde, KeyModifiers.Alt);
+ HotKeyManager.HotKeyPressed += HotKeyManager_HotKeyPressed;
+
+ void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e) {
+ // if (e.Key == Keys.Oemtilde && e.Modifiers == KeyModifiers.Alt) {
+ // TrackWows();
+ // return;
+ // }
+
+ int index;
+ if (e.Key >= Keys.D0 && e.Key <= Keys.D9) {
+ index = e.Key - Keys.D0;
+ } else if (e.Key >= Keys.NumPad1 && e.Key <= Keys.NumPad9) {
+ index = 10 + (e.Key - Keys.NumPad1);
+ } else {
+ return;
+ }
+
+ if (e.Modifiers == KeyModifiers.Alt) {
+ if (IsCapsLockOn()) {
+ Swap(index);
+ } else {
+ TabTo(index);
+ }
+ }
+ }
+
+ Console.CancelKeyPress += (sender, e) => { Process.GetCurrentProcess().Kill(); };
+ while (true) System.Threading.Thread.Sleep(100000);
+ }
+ }
}
diff --git a/DD2Switcher/Properties/Resources.Designer.cs b/DD2Switcher/Properties/Resources.Designer.cs
index bb91864..6e4205e 100644
--- a/DD2Switcher/Properties/Resources.Designer.cs
+++ b/DD2Switcher/Properties/Resources.Designer.cs
@@ -9,55 +9,53 @@
//------------------------------------------------------------------------------
namespace DD2Switcher.Properties {
-using System;
+ using System;
-///
-/// A strongly-typed resource class, for looking up localized strings, etc.
-///
-// This class was auto-generated by the StronglyTypedResourceBuilder
-// class via a tool like ResGen or Visual Studio.
-// To add or remove a member, edit your .ResX file then rerun ResGen
-// with the /str option, or rebuild your VS project.
-[global::System.CodeDom.Compiler.GeneratedCodeAttribute(
- "System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
-[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
-internal class Resources {
+ ///
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ ///
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder",
+ "17.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+ private static global::System.Resources.ResourceManager resourceMan;
- private static global::System.Resources.ResourceManager resourceMan;
+ private static global::System.Globalization.CultureInfo resourceCulture;
- private static global::System.Globalization.CultureInfo resourceCulture;
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance",
+ "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {}
- [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute(
- "Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
- internal Resources() {}
+ ///
+ /// Returns the cached ResourceManager instance used by this class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(
+ global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager(
+ "DD2Switcher.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
- ///
- /// Returns the cached ResourceManager instance used by this class.
- ///
- [global::System.ComponentModel.EditorBrowsableAttribute(
- global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Resources.ResourceManager ResourceManager {
- get {
- if (object.ReferenceEquals(resourceMan, null)) {
- global::System.Resources.ResourceManager temp =
- new global::System.Resources.ResourceManager(
- "DD2Switcher.Properties.Resources", typeof(Resources).Assembly);
- resourceMan = temp;
- }
- return resourceMan;
+ ///
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(
+ global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get { return resourceCulture; }
+ set { resourceCulture = value; }
+ }
}
- }
-
- ///
- /// Overrides the current thread's CurrentUICulture property for all
- /// resource lookups using this strongly typed resource class.
- ///
- [global::System.ComponentModel.EditorBrowsableAttribute(
- global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Globalization.CultureInfo Culture {
- get { return resourceCulture; }
- set { resourceCulture = value; }
- }
-}
}
diff --git a/DD2Switcher/Properties/Settings.Designer.cs b/DD2Switcher/Properties/Settings.Designer.cs
index 027a05d..bc81356 100644
--- a/DD2Switcher/Properties/Settings.Designer.cs
+++ b/DD2Switcher/Properties/Settings.Designer.cs
@@ -9,18 +9,16 @@
//------------------------------------------------------------------------------
namespace DD2Switcher.Properties {
-[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
-[global::System.CodeDom.Compiler.GeneratedCodeAttribute(
- "Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator",
- "11.0.0.0")]
-internal sealed partial class Settings
- : global::System.Configuration.ApplicationSettingsBase {
- private static Settings defaultInstance =
- ((Settings)(global::System.Configuration.ApplicationSettingsBase
- .Synchronized(new Settings())));
- public static Settings Default {
- get { return defaultInstance; }
- }
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute(
+ "Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.14.0.0")]
+ internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+ private static Settings defaultInstance =
+ ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+ public static Settings Default {
+ get { return defaultInstance; }
+ }
+ }
}
-}
\ No newline at end of file