Fix some shit and code format
Also now end is to swap windows
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
<Deterministic>true</Deterministic>
|
<Deterministic>true</Deterministic>
|
||||||
<LangVersion>10</LangVersion>
|
<LangVersion>9.0</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
|
70
DD2Switcher/Form1.Designer.cs
generated
70
DD2Switcher/Form1.Designer.cs
generated
@@ -1,40 +1,36 @@
|
|||||||
namespace DD2Switcher
|
namespace DD2Switcher {
|
||||||
{
|
partial class Form1 {
|
||||||
partial class Form1
|
/// <summary>
|
||||||
{
|
/// Required designer variable.
|
||||||
/// <summary>
|
/// </summary>
|
||||||
/// Required designer variable.
|
private System.ComponentModel.IContainer components = null;
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clean up any resources being used.
|
/// Clean up any resources being used.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
/// <param name="disposing">true if managed resources should be disposed;
|
||||||
protected override void Dispose(bool disposing)
|
/// otherwise, false.</param>
|
||||||
{
|
protected override void Dispose(bool disposing) {
|
||||||
if (disposing && (components != null))
|
if (disposing && (components != null)) {
|
||||||
{
|
components.Dispose();
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Required method for Designer support - do not modify
|
|
||||||
/// the contents of this method with the code editor.
|
|
||||||
/// </summary>
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
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
|
||||||
|
}
|
||||||
}
|
}
|
@@ -1,9 +1,7 @@
|
|||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace DD2Switcher;
|
namespace DD2Switcher {
|
||||||
|
|
||||||
public partial class Form1 : Form {
|
public partial class Form1 : Form {
|
||||||
public Form1() {
|
public Form1() { InitializeComponent(); }
|
||||||
InitializeComponent();
|
}
|
||||||
}
|
|
||||||
}
|
}
|
@@ -3,103 +3,110 @@ using System.Runtime.InteropServices;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace DD2Switcher;
|
namespace DD2Switcher {
|
||||||
|
|
||||||
public static class HotKeyManager {
|
public static class HotKeyManager {
|
||||||
private static volatile MessageWindow _wnd;
|
private static volatile MessageWindow _wnd;
|
||||||
private static volatile IntPtr _hwnd;
|
private static volatile IntPtr _hwnd;
|
||||||
private static readonly ManualResetEvent _windowReadyEvent = new(false);
|
private static readonly ManualResetEvent _windowReadyEvent = new(false);
|
||||||
|
|
||||||
private static int _id;
|
private static int _id;
|
||||||
|
|
||||||
static HotKeyManager() {
|
static HotKeyManager() {
|
||||||
var messageLoop = new Thread(delegate() { Application.Run(new MessageWindow()); });
|
var messageLoop =
|
||||||
messageLoop.Name = "MessageLoopThread";
|
new Thread(delegate() { Application.Run(new MessageWindow()); });
|
||||||
messageLoop.IsBackground = true;
|
messageLoop.Name = "MessageLoopThread";
|
||||||
messageLoop.Start();
|
messageLoop.IsBackground = true;
|
||||||
|
messageLoop.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static event EventHandler<HotKeyEventArgs> 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 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 UnRegisterHotKeyInternal(IntPtr hwnd, int id) {
|
||||||
|
UnregisterHotKey(_hwnd, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 UnregisterHotKey(IntPtr hWnd, int id);
|
||||||
|
|
||||||
|
private delegate void RegisterHotKeyDelegate(IntPtr hwnd, int id,
|
||||||
|
uint modifiers, uint key);
|
||||||
|
|
||||||
|
private delegate void UnRegisterHotKeyDelegate(IntPtr hwnd, int id);
|
||||||
|
|
||||||
|
private class MessageWindow : Form {
|
||||||
|
private const int WM_HOTKEY = 0x312;
|
||||||
|
|
||||||
|
public MessageWindow() {
|
||||||
|
_wnd = this;
|
||||||
|
_hwnd = Handle;
|
||||||
|
_windowReadyEvent.Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static event EventHandler<HotKeyEventArgs> HotKeyPressed;
|
protected override void WndProc(ref Message m) {
|
||||||
|
if (m.Msg == WM_HOTKEY) {
|
||||||
|
var e = new HotKeyEventArgs(m.LParam);
|
||||||
|
OnHotKeyPressed(e);
|
||||||
|
}
|
||||||
|
|
||||||
public static int RegisterHotKey(Keys key, KeyModifiers modifiers) {
|
base.WndProc(ref m);
|
||||||
_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) {
|
protected override void SetVisibleCore(bool value) {
|
||||||
_wnd.Invoke(new UnRegisterHotKeyDelegate(UnRegisterHotKeyInternal), _hwnd, id);
|
// Ensure the window never becomes visible
|
||||||
}
|
base.SetVisibleCore(false);
|
||||||
|
|
||||||
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 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 UnregisterHotKey(IntPtr hWnd, int id);
|
|
||||||
|
|
||||||
private delegate void RegisterHotKeyDelegate(IntPtr hwnd, int id, uint modifiers, uint key);
|
|
||||||
|
|
||||||
private delegate void UnRegisterHotKeyDelegate(IntPtr hwnd, int id);
|
|
||||||
|
|
||||||
private class MessageWindow : Form {
|
|
||||||
private const int WM_HOTKEY = 0x312;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class HotKeyEventArgs : EventArgs {
|
public class HotKeyEventArgs : EventArgs {
|
||||||
public readonly Keys Key;
|
public readonly Keys Key;
|
||||||
public readonly KeyModifiers Modifiers;
|
public readonly KeyModifiers Modifiers;
|
||||||
|
|
||||||
public HotKeyEventArgs(Keys key, KeyModifiers modifiers) {
|
public HotKeyEventArgs(Keys key, KeyModifiers modifiers) {
|
||||||
Key = key;
|
Key = key;
|
||||||
Modifiers = modifiers;
|
Modifiers = modifiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HotKeyEventArgs(IntPtr hotKeyParam) {
|
public HotKeyEventArgs(IntPtr hotKeyParam) {
|
||||||
var param = (uint)hotKeyParam.ToInt64();
|
var param = (uint)hotKeyParam.ToInt64();
|
||||||
Key = (Keys)((param & 0xffff0000) >> 16);
|
Key = (Keys)((param & 0xffff0000) >> 16);
|
||||||
Modifiers = (KeyModifiers)(param & 0x0000ffff);
|
Modifiers = (KeyModifiers)(param & 0x0000ffff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Flags]
|
[Flags]
|
||||||
public enum KeyModifiers {
|
public enum KeyModifiers {
|
||||||
Alt = 1,
|
Alt = 1,
|
||||||
Control = 2,
|
Control = 2,
|
||||||
Shift = 4,
|
Shift = 4,
|
||||||
Windows = 8,
|
Windows = 8,
|
||||||
NoRepeat = 0x4000
|
NoRepeat = 0x4000
|
||||||
|
}
|
||||||
}
|
}
|
@@ -4,259 +4,266 @@ using System.Diagnostics;
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace DD2Switcher;
|
namespace DD2Switcher {
|
||||||
|
|
||||||
internal static class Program {
|
internal static class Program {
|
||||||
private static int NumProc = 19;
|
private static int NumProc = 19;
|
||||||
private static Process[] windows = new Process[NumProc];
|
private static Process[] windows = new Process[NumProc];
|
||||||
private static int ActiveIndex = -1;
|
private static int ActiveIndex = -1;
|
||||||
|
|
||||||
private static readonly IntPtr defaultAffinity = new(0xFF000000);
|
private static readonly IntPtr defaultAffinity = new(0xFF000000);
|
||||||
private static readonly IntPtr fullAffinity = new(0xFFFFFFFF);
|
private static readonly IntPtr fullAffinity = new(0xFFFFFFFF);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
public static extern IntPtr GetForegroundWindow();
|
public static extern IntPtr GetForegroundWindow();
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||||
|
|
||||||
[DllImport("kernel32.dll", SetLastError = true)]
|
[DllImport("kernel32.dll", SetLastError = true)]
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return:MarshalAs(UnmanagedType.Bool)]
|
||||||
static extern bool AllocConsole();
|
static extern bool AllocConsole();
|
||||||
|
|
||||||
private static void CleanWindows() {
|
private static void CleanWindows() {
|
||||||
for (int i = 0; i < NumProc; i++) {
|
for (int i = 0; i < NumProc; i++) {
|
||||||
var window = windows[i];
|
var window = windows[i];
|
||||||
if (window == null) continue;
|
if (window == null)
|
||||||
if (window.MainWindowHandle == IntPtr.Zero) {
|
continue;
|
||||||
Console.WriteLine($"Window at index {i} has no main window, removing from tracked windows");
|
if (window.MainWindowHandle == IntPtr.Zero) {
|
||||||
windows[i] = null;
|
Console.WriteLine(
|
||||||
}
|
$"Window at index {i} has no main window, removing from tracked windows");
|
||||||
}
|
windows[i] = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void AdjustAffinities() {
|
private static void AdjustAffinities() {
|
||||||
CleanWindows();
|
CleanWindows();
|
||||||
for (int i = 0; i < NumProc; i++) {
|
for (int i = 0; i < NumProc; i++) {
|
||||||
var window = windows[i];
|
var window = windows[i];
|
||||||
if (window == null) continue;
|
if (window == null)
|
||||||
if (i != ActiveIndex) {
|
continue;
|
||||||
try {
|
if (i != ActiveIndex) {
|
||||||
window.ProcessorAffinity = defaultAffinity;
|
try {
|
||||||
}
|
window.ProcessorAffinity = defaultAffinity;
|
||||||
catch (Exception e) {
|
} catch (Exception e) {
|
||||||
windows[i] = null;
|
windows[i] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var active = windows[ActiveIndex];
|
var active = windows[ActiveIndex];
|
||||||
if (active != null) {
|
if (active != null) {
|
||||||
try {
|
try {
|
||||||
active.ProcessorAffinity = fullAffinity;
|
active.ProcessorAffinity = fullAffinity;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
windows[ActiveIndex] = null;
|
||||||
windows[ActiveIndex] = null;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static void AdjustPriorities() {
|
private static void AdjustPriorities() {
|
||||||
CleanWindows();
|
CleanWindows();
|
||||||
for (int i = 0; i < NumProc; i++) {
|
for (int i = 0; i < NumProc; i++) {
|
||||||
var window = windows[i];
|
var window = windows[i];
|
||||||
if (window == null) continue;
|
if (window == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (i != ActiveIndex) {
|
if (i != ActiveIndex) {
|
||||||
try {
|
try {
|
||||||
window.PriorityClass = ProcessPriorityClass.Idle;
|
window.PriorityClass = ProcessPriorityClass.Idle;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
windows[i] = null;
|
||||||
windows[i] = null;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var active = windows[ActiveIndex];
|
var active = windows[ActiveIndex];
|
||||||
if (active != null) {
|
if (active != null) {
|
||||||
try {
|
try {
|
||||||
active.PriorityClass = ProcessPriorityClass.High;
|
active.PriorityClass = ProcessPriorityClass.High;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
windows[ActiveIndex] = null;
|
||||||
windows[ActiveIndex] = null;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static Process GetForegroundProcess() {
|
private static Process GetForegroundProcess() {
|
||||||
var foregroundWindow = GetForegroundWindow();
|
var foregroundWindow = GetForegroundWindow();
|
||||||
var process = Process.GetProcesses();
|
var process = Process.GetProcesses();
|
||||||
Process foregroundProcess = null;
|
Process foregroundProcess = null;
|
||||||
foreach (var p in process)
|
foreach (var p in process)
|
||||||
if (foregroundWindow == p.MainWindowHandle) {
|
if (foregroundWindow == p.MainWindowHandle) {
|
||||||
foregroundProcess = p;
|
foregroundProcess = p;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foregroundProcess == null) return null;
|
if (foregroundProcess == null)
|
||||||
return foregroundProcess;
|
return null;
|
||||||
}
|
return foregroundProcess;
|
||||||
|
}
|
||||||
|
|
||||||
private static Boolean ProcessTracked(int id) {
|
private static Boolean ProcessTracked(int id) {
|
||||||
for (int i = 0; i < NumProc; i++) {
|
for (int i = 0; i < NumProc; i++) {
|
||||||
if (windows[i] != null && windows[i].Id == id) {
|
if (windows[i] != null && windows[i].Id == id) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Track(Process process) {
|
private static void Track(Process process) {
|
||||||
for (int i = 0; i < NumProc; i++) {
|
for (int i = 0; i < NumProc; i++) {
|
||||||
if (windows[i] == null) {
|
if (windows[i] == null) {
|
||||||
windows[i] = process;
|
windows[i] = process;
|
||||||
Console.WriteLine($"Added {process.ProcessName} to tracked windows at index {i}");
|
Console.WriteLine(
|
||||||
return;
|
$"Added {process.ProcessName} to tracked windows at index {i}");
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void TrackWows() {
|
private static void TrackWows() {
|
||||||
CleanWindows();
|
CleanWindows();
|
||||||
var processes = Process.GetProcesses();
|
var processes = Process.GetProcesses();
|
||||||
foreach (var process in processes) {
|
foreach (var process in processes) {
|
||||||
if (process.ProcessName == "UWow-64") {
|
if (process.ProcessName == "UWow-64") {
|
||||||
Console.WriteLine($"Found UWow-64 at pid {process.Id}");
|
Console.WriteLine($"Found UWow-64 at pid {process.Id}");
|
||||||
if (ProcessTracked(process.Id))
|
if (ProcessTracked(process.Id))
|
||||||
continue;
|
continue;
|
||||||
Track(process);
|
Track(process);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Swap(int index) {
|
private static void Swap(int index) {
|
||||||
index = (index - 1) % NumProc;
|
index = (index - 1) % NumProc;
|
||||||
if (index < 0) index = NumProc - 1;
|
if (index < 0)
|
||||||
if (index >= NumProc) return;
|
index = NumProc - 1;
|
||||||
CleanWindows();
|
if (index >= NumProc)
|
||||||
Console.WriteLine($"Swapping window at index {index}");
|
return;
|
||||||
var process = GetForegroundProcess();
|
CleanWindows();
|
||||||
if (process == null) return;
|
Console.WriteLine($"Swapping window at index {index}");
|
||||||
Console.WriteLine($"Foreground process: {process}");
|
var process = GetForegroundProcess();
|
||||||
bool found = false;
|
if (process == null)
|
||||||
|
return;
|
||||||
|
Console.WriteLine($"Foreground process: {process}");
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
for (int i = 0; i < NumProc; i++) {
|
for (int i = 0; i < NumProc; i++) {
|
||||||
var window = windows[i];
|
var window = windows[i];
|
||||||
if (window != null && window.Id == process.Id) {
|
if (window != null && window.Id == process.Id) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
for (int i = 0; i < NumProc; i++) {
|
for (int i = 0; i < NumProc; i++) {
|
||||||
var window = windows[i];
|
var window = windows[i];
|
||||||
if (window == null) {
|
if (window == null) {
|
||||||
Console.WriteLine($"Adding foreground window to tracked at index {i}...");
|
Console.WriteLine(
|
||||||
windows[i] = process;
|
$"Adding foreground window to tracked at index {i}...");
|
||||||
}
|
windows[i] = process;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < NumProc; i++) {
|
for (int i = 0; i < NumProc; i++) {
|
||||||
var window = windows[i];
|
var window = windows[i];
|
||||||
if (window != null && window.Id == process.Id) {
|
if (window != null && window.Id == process.Id) {
|
||||||
windows[i] = windows[index];
|
windows[i] = windows[index];
|
||||||
windows[index] = window;
|
windows[index] = window;
|
||||||
Console.WriteLine($"Swapped window at index {i} to {index}");
|
Console.WriteLine($"Swapped window at index {i} to {index}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void TabTo(int index) {
|
private static void TabTo(int index) {
|
||||||
index = (index - 1) % NumProc;
|
index = (index - 1) % NumProc;
|
||||||
if (index < 0) index = NumProc - 1;
|
if (index < 0)
|
||||||
if (index >= NumProc) return;
|
index = NumProc - 1;
|
||||||
CleanWindows();
|
if (index >= NumProc)
|
||||||
Console.WriteLine($"Tab to window at index {index}");
|
return;
|
||||||
|
CleanWindows();
|
||||||
|
Console.WriteLine($"Tab to window at index {index}");
|
||||||
|
|
||||||
var window = windows[index];
|
var window = windows[index];
|
||||||
if (window == null || window.MainWindowHandle == IntPtr.Zero) {
|
if (window == null || window.MainWindowHandle == IntPtr.Zero) {
|
||||||
Console.WriteLine($"Window at index {index} does not exist, removing from tracked windows");
|
Console.WriteLine(
|
||||||
windows[index] = null;
|
$"Window at index {index} does not exist, removing from tracked windows");
|
||||||
}
|
windows[index] = null;
|
||||||
else {
|
} else {
|
||||||
SetForegroundWindow(window.MainWindowHandle);
|
SetForegroundWindow(window.MainWindowHandle);
|
||||||
ActiveIndex = index;
|
ActiveIndex = index;
|
||||||
AdjustAffinities();
|
AdjustAffinities();
|
||||||
AdjustPriorities();
|
AdjustPriorities();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
private static void Main() {
|
private static void Main() {
|
||||||
//AllocConsole();
|
// AllocConsole();
|
||||||
|
|
||||||
var processes = Process.GetProcesses();
|
var processes = Process.GetProcesses();
|
||||||
var currentProcess = Process.GetCurrentProcess();
|
var currentProcess = Process.GetCurrentProcess();
|
||||||
|
|
||||||
foreach (var process in processes)
|
foreach (var process in processes)
|
||||||
if (process.Id != currentProcess.Id && process.ProcessName == currentProcess.ProcessName) {
|
if (process.Id != currentProcess.Id &&
|
||||||
process.Kill();
|
process.ProcessName == currentProcess.ProcessName) {
|
||||||
Process.GetCurrentProcess().Kill();
|
process.Kill();
|
||||||
}
|
Process.GetCurrentProcess().Kill();
|
||||||
|
}
|
||||||
|
|
||||||
long delLast = 0;
|
long delLast = 0;
|
||||||
HotKeyManager.RegisterHotKey(Keys.Decimal, KeyModifiers.NoRepeat);
|
HotKeyManager.RegisterHotKey(Keys.End, KeyModifiers.NoRepeat);
|
||||||
// Register main number keys (0-9)
|
// Register main number keys (0-9)
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
HotKeyManager.RegisterHotKey(Keys.D0 + i, KeyModifiers.Alt);
|
HotKeyManager.RegisterHotKey(Keys.D0 + i, KeyModifiers.Alt);
|
||||||
|
|
||||||
// Register numpad keys (1-9)
|
// Register numpad keys (1-9)
|
||||||
for (int i = 0; i < 9; i++)
|
for (int i = 0; i < 9; i++)
|
||||||
HotKeyManager.RegisterHotKey(Keys.NumPad1 + i, KeyModifiers.Alt);
|
HotKeyManager.RegisterHotKey(Keys.NumPad1 + i, KeyModifiers.Alt);
|
||||||
|
|
||||||
|
HotKeyManager.RegisterHotKey(Keys.Oemtilde, KeyModifiers.Alt);
|
||||||
|
HotKeyManager.HotKeyPressed += HotKeyManager_HotKeyPressed;
|
||||||
|
|
||||||
HotKeyManager.RegisterHotKey(Keys.Oemtilde, KeyModifiers.Alt);
|
void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e) {
|
||||||
HotKeyManager.HotKeyPressed += HotKeyManager_HotKeyPressed;
|
if (e.Key == Keys.Oemtilde && e.Modifiers == KeyModifiers.Alt) {
|
||||||
|
TrackWows();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e) {
|
long now = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
||||||
if (e.Key == Keys.Oemtilde && e.Modifiers == KeyModifiers.Alt) {
|
if (e.Key == Keys.End)
|
||||||
TrackWows();
|
delLast = now;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
long now = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
int index;
|
||||||
if (e.Key == Keys.Decimal)
|
if (e.Key >= Keys.D0 && e.Key <= Keys.D9) {
|
||||||
delLast = now;
|
index = e.Key - Keys.D0;
|
||||||
|
} else if (e.Key >= Keys.NumPad1 && e.Key <= Keys.NumPad9) {
|
||||||
|
index = 10 + (e.Key - Keys.NumPad1);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int index;
|
long cocksucker = DateTime.Now.Second;
|
||||||
if (e.Key >= Keys.D0 && e.Key <= Keys.D9) {
|
Console.WriteLine(cocksucker);
|
||||||
index = e.Key - Keys.D0;
|
if (e.Modifiers == KeyModifiers.Alt) {
|
||||||
}
|
if (now - delLast <= 1) {
|
||||||
else if (e.Key >= Keys.NumPad1 && e.Key <= Keys.NumPad9) {
|
Swap(index);
|
||||||
index = 10 + (e.Key - Keys.NumPad1);
|
delLast = 0;
|
||||||
}
|
} else {
|
||||||
else {
|
TabTo(index);
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
long cocksucker = DateTime.Now.Second;
|
Console.CancelKeyPress +=
|
||||||
Console.WriteLine(cocksucker);
|
(sender, e) => { Process.GetCurrentProcess().Kill(); };
|
||||||
if (e.Modifiers == KeyModifiers.Alt) {
|
while (true)
|
||||||
if (now - delLast <= 1) {
|
System.Threading.Thread.Sleep(100000);
|
||||||
Swap(index);
|
}
|
||||||
delLast = 0;
|
}
|
||||||
} else {
|
|
||||||
TabTo(index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.CancelKeyPress += (sender, e) => { Process.GetCurrentProcess().Kill(); };
|
|
||||||
while (true)
|
|
||||||
System.Threading.Thread.Sleep(100000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -4,22 +4,23 @@ using System.Runtime.InteropServices;
|
|||||||
// General Information about an assembly is controlled through the following
|
// General Information about an assembly is controlled through the following
|
||||||
// set of attributes. Change these attribute values to modify the information
|
// set of attributes. Change these attribute values to modify the information
|
||||||
// associated with an assembly.
|
// associated with an assembly.
|
||||||
[assembly: AssemblyTitle("DD2Switcher")]
|
[assembly:AssemblyTitle("DD2Switcher")]
|
||||||
[assembly: AssemblyDescription("")]
|
[assembly:AssemblyDescription("")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly:AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly:AssemblyCompany("")]
|
||||||
[assembly: AssemblyProduct("DD2Switcher")]
|
[assembly:AssemblyProduct("DD2Switcher")]
|
||||||
[assembly: AssemblyCopyright("Copyright © 2022")]
|
[assembly:AssemblyCopyright("Copyright © 2022")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly:AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly:AssemblyCulture("")]
|
||||||
|
|
||||||
// Setting ComVisible to false makes the types in this assembly not visible
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
// to COM components. If you need to access a type in this assembly from
|
// to COM components. If you need to access a type in this assembly from
|
||||||
// COM, set the ComVisible attribute to true on that type.
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
[assembly: ComVisible(false)]
|
[assembly:ComVisible(false)]
|
||||||
|
|
||||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
// The following GUID is for the ID of the typelib if this project is exposed to
|
||||||
[assembly: Guid("2AC26899-8E27-4B96-85A9-C387186EAD27")]
|
// COM
|
||||||
|
[assembly:Guid("2AC26899-8E27-4B96-85A9-C387186EAD27")]
|
||||||
|
|
||||||
// Version information for an assembly consists of the following four values:
|
// Version information for an assembly consists of the following four values:
|
||||||
//
|
//
|
||||||
@@ -28,8 +29,7 @@ using System.Runtime.InteropServices;
|
|||||||
// Build Number
|
// Build Number
|
||||||
// Revision
|
// Revision
|
||||||
//
|
//
|
||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision
|
||||||
// by using the '*' as shown below:
|
// Numbers by using the '*' as shown below: [assembly: AssemblyVersion("1.0.*")]
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
[assembly:AssemblyVersion("1.0.0.0")]
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
[assembly:AssemblyFileVersion("1.0.0.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
100
DD2Switcher/Properties/Resources.Designer.cs
generated
100
DD2Switcher/Properties/Resources.Designer.cs
generated
@@ -9,55 +9,55 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace DD2Switcher.Properties {
|
namespace DD2Switcher.Properties {
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
/// <summary>
|
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
/// </summary>
|
||||||
/// </summary>
|
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
// class via a tool like ResGen or Visual Studio.
|
||||||
// class via a tool like ResGen or Visual Studio.
|
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
// with the /str option, or rebuild your VS project.
|
||||||
// with the /str option, or rebuild your VS project.
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
"System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
internal class Resources {
|
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")]
|
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute(
|
||||||
internal Resources() {
|
"Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||||
}
|
internal Resources() {}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the cached ResourceManager instance used by this class.
|
/// Returns the cached ResourceManager instance used by this class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
[global::System.ComponentModel.EditorBrowsableAttribute(
|
||||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
get {
|
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||||
if (object.ReferenceEquals(resourceMan, null)) {
|
get {
|
||||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DD2Switcher.Properties.Resources", typeof(Resources).Assembly);
|
if (object.ReferenceEquals(resourceMan, null)) {
|
||||||
resourceMan = temp;
|
global::System.Resources.ResourceManager temp =
|
||||||
}
|
new global::System.Resources.ResourceManager(
|
||||||
return resourceMan;
|
"DD2Switcher.Properties.Resources", typeof(Resources).Assembly);
|
||||||
}
|
resourceMan = temp;
|
||||||
}
|
}
|
||||||
|
return resourceMan;
|
||||||
/// <summary>
|
|
||||||
/// Overrides the current thread's CurrentUICulture property for all
|
|
||||||
/// resource lookups using this strongly typed resource class.
|
|
||||||
/// </summary>
|
|
||||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
|
||||||
internal static global::System.Globalization.CultureInfo Culture {
|
|
||||||
get {
|
|
||||||
return resourceCulture;
|
|
||||||
}
|
|
||||||
set {
|
|
||||||
resourceCulture = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Overrides the current thread's CurrentUICulture property for all
|
||||||
|
/// resource lookups using this strongly typed resource class.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(
|
||||||
|
global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Globalization.CultureInfo Culture {
|
||||||
|
get { return resourceCulture; }
|
||||||
|
set { resourceCulture = value; }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
28
DD2Switcher/Properties/Settings.Designer.cs
generated
28
DD2Switcher/Properties/Settings.Designer.cs
generated
@@ -8,19 +8,19 @@
|
|||||||
// </auto-generated>
|
// </auto-generated>
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace DD2Switcher.Properties
|
namespace DD2Switcher.Properties {
|
||||||
{
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(
|
"Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator",
|
||||||
"Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
|
"11.0.0.0")]
|
||||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
internal sealed partial class Settings
|
||||||
{
|
: global::System.Configuration.ApplicationSettingsBase {
|
||||||
private static Settings defaultInstance =
|
private static Settings defaultInstance =
|
||||||
((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
((Settings)(global::System.Configuration.ApplicationSettingsBase
|
||||||
|
.Synchronized(new Settings())));
|
||||||
|
|
||||||
public static Settings Default
|
public static Settings Default {
|
||||||
{
|
get { return defaultInstance; }
|
||||||
get { return defaultInstance; }
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user