Compare commits
2 Commits
6cee7038bd
...
6a4e25cdb8
Author | SHA1 | Date | |
---|---|---|---|
6a4e25cdb8 | |||
a9024539a4 |
@@ -7,7 +7,7 @@ using System.Windows.Forms;
|
|||||||
namespace DD2Switcher;
|
namespace DD2Switcher;
|
||||||
|
|
||||||
internal static class Program {
|
internal static class Program {
|
||||||
private static int NumProc = 9;
|
private static int NumProc = 10;
|
||||||
private static Process[] windows = new Process[NumProc];
|
private static Process[] windows = new Process[NumProc];
|
||||||
private static int ActiveIndex = -1;
|
private static int ActiveIndex = -1;
|
||||||
|
|
||||||
@@ -102,25 +102,35 @@ internal static class Program {
|
|||||||
return foregroundProcess;
|
return foregroundProcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Boolean ProcessTracked(int id) {
|
||||||
|
for (int i = 0; i < NumProc; i++) {
|
||||||
|
if (windows[i] != null && windows[i].Id == id) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Track(Process process) {
|
||||||
|
for (int i = 0; i < NumProc; i++) {
|
||||||
|
if (windows[i] == null) {
|
||||||
|
windows[i] = process;
|
||||||
|
Console.WriteLine($"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}");
|
||||||
for (int i = 0; i < NumProc; i++) {
|
if (ProcessTracked(process.Id))
|
||||||
if (windows[i] != null && windows[i].Id == process.Id) {
|
continue;
|
||||||
Console.WriteLine($"UWow-64 is already tracked at index {i}");
|
Track(process);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int i = 0; i < NumProc; i++) {
|
|
||||||
if (windows[i] == null) {
|
|
||||||
windows[i] = process;
|
|
||||||
Console.WriteLine($"Added UWow-64 to tracked windows at index {i}");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,7 +142,7 @@ internal static class Program {
|
|||||||
Console.WriteLine($"Foreground process: {process}");
|
Console.WriteLine($"Foreground process: {process}");
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
for (int i = 0; i < 9; 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;
|
||||||
@@ -141,7 +151,7 @@ internal static class Program {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
for (int i = 0; i < 9; 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($"Adding foreground window to tracked at index {i}...");
|
||||||
@@ -150,7 +160,7 @@ internal static class Program {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 9; 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];
|
||||||
@@ -191,7 +201,7 @@ internal static class Program {
|
|||||||
Process.GetCurrentProcess().Kill();
|
Process.GetCurrentProcess().Kill();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 9; i++) {
|
for (int i = 0; i < NumProc; i++) {
|
||||||
windows[i] = null;
|
windows[i] = null;
|
||||||
HotKeyManager.RegisterHotKey(Keys.D1 + i, KeyModifiers.Alt);
|
HotKeyManager.RegisterHotKey(Keys.D1 + i, KeyModifiers.Alt);
|
||||||
HotKeyManager.RegisterHotKey(Keys.D1 + i, KeyModifiers.Alt | KeyModifiers.Shift);
|
HotKeyManager.RegisterHotKey(Keys.D1 + i, KeyModifiers.Alt | KeyModifiers.Shift);
|
||||||
@@ -219,4 +229,4 @@ internal static class Program {
|
|||||||
while (true)
|
while (true)
|
||||||
System.Threading.Thread.Sleep(100000);
|
System.Threading.Thread.Sleep(100000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user