Skip to content

Commit

Permalink
Focus game window when it spawns
Browse files Browse the repository at this point in the history
This fixes rare occasions when launcher fails to focus game properly.
  • Loading branch information
keton committed Jan 26, 2024
1 parent 2080c3f commit eac517f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Chihuahua.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ await AnsiConsole.Status()
Helpers.ExitWithMessage(ctx, "Timed out while waiting for game process");
}
Helpers.focusGameWindow(gameExe);
ConsoleCtrlEventArgs.gameExe = gameExe;
if (SetConsoleCtrlHandler(ConsoleCloseHandler, true) == false) {
Helpers.ExitWithMessage(ctx, "Failed to attach console close handler.");
Expand Down
11 changes: 11 additions & 0 deletions Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,15 @@ public static bool IsUnrealExecutable(string gameExe) {

return null;
}

[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
public static void focusGameWindow(string gameExe) {
var mainGameProcess = Helpers.GetMainGameProcess(gameExe);
if (mainGameProcess == null) {
Logger.Warn($"Failed to find main game process for {gameExe}");
return;
}
SwitchToThisWindow(mainGameProcess.Id, true);
}
}

0 comments on commit eac517f

Please sign in to comment.