Compare commits

...

2 Commits

View File

@@ -28,7 +28,8 @@ internal static class Program {
static extern bool AllocConsole(); static extern bool AllocConsole();
[DllImport("user32.dll")] [DllImport("user32.dll")]
private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo); private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags,
int dwExtraInfo);
private static void CleanWindows() { private static void CleanWindows() {
for (int i = 0; i < NumProc; i++) { for (int i = 0; i < NumProc; i++) {
@@ -120,28 +121,47 @@ internal static class Program {
} }
private static void Track(Process process) { private static void Track(Process process) {
// First find the first null slot
int firstNullIndex = -1;
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; firstNullIndex = i;
Console.WriteLine( break;
$"Added {process.ProcessName} to tracked windows at index {i}");
return;
} }
} }
if (firstNullIndex == -1) {
Console.WriteLine("No slots available for tracking");
return;
}
// 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++;
}
}
// Add the new process at the first null slot
windows[firstNullIndex] = process;
Console.WriteLine(
$"Added {process.ProcessName} to tracked windows at index {firstNullIndex}");
} }
private static void TrackWows() { // private static void TrackWows() {
CleanWindows(); // CleanWindows();
var processes = Process.GetProcesses().OrderBy(p => p.Id).ToList(); // var processes = Process.GetProcesses().OrderBy(p => p.Id).ToList();
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;
@@ -172,6 +192,7 @@ internal static class Program {
Console.WriteLine( Console.WriteLine(
$"Adding foreground window to tracked at index {i}..."); $"Adding foreground window to tracked at index {i}...");
windows[i] = process; windows[i] = process;
break;
} }
} }
} }
@@ -183,7 +204,7 @@ internal static class Program {
windows[index] = window; windows[index] = window;
Console.WriteLine($"Swapped window at index {i} to {index}"); Console.WriteLine($"Swapped window at index {i} to {index}");
// Toggle scroll lock off // Toggle scroll lock off
keybd_event(0x91, 0, 0, 0); // KEYEVENTF_KEYDOWN keybd_event(0x91, 0, 0, 0); // KEYEVENTF_KEYDOWN
keybd_event(0x91, 0, 0x0002, 0); // KEYEVENTF_KEYUP keybd_event(0x91, 0, 0x0002, 0); // KEYEVENTF_KEYUP
return; return;
} }
@@ -212,9 +233,7 @@ internal static class Program {
} }
} }
private static bool IsScrollLockOn() { private static bool IsScrollLockOn() { return (GetKeyState(0x91) & 1) == 1; }
return (GetKeyState(0x91) & 1) == 1;
}
[STAThread] [STAThread]
private static void Main() { private static void Main() {
@@ -243,10 +262,10 @@ internal static class Program {
HotKeyManager.HotKeyPressed += HotKeyManager_HotKeyPressed; HotKeyManager.HotKeyPressed += HotKeyManager_HotKeyPressed;
void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e) { void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e) {
if (e.Key == Keys.Oemtilde && e.Modifiers == KeyModifiers.Alt) { // if (e.Key == Keys.Oemtilde && e.Modifiers == KeyModifiers.Alt) {
TrackWows(); // TrackWows();
return; // return;
} // }
int index; int index;
if (e.Key >= Keys.D0 && e.Key <= Keys.D9) { if (e.Key >= Keys.D0 && e.Key <= Keys.D9) {