From 05b808ef41a32f003b37d55e65d3b52ad15d3cc9 Mon Sep 17 00:00:00 2001 From: kpreisser Date: Sat, 11 Aug 2018 14:28:49 +0200 Subject: [PATCH] Follow-Up: Only bring the window to the foreground when starting the loop or the window is a different one. --- .../Core/Environment/StandardInteractionProvider.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/TTMouseclickSimulator/Core/Environment/StandardInteractionProvider.cs b/TTMouseclickSimulator/Core/Environment/StandardInteractionProvider.cs index 075bf89..dbe7048 100644 --- a/TTMouseclickSimulator/Core/Environment/StandardInteractionProvider.cs +++ b/TTMouseclickSimulator/Core/Environment/StandardInteractionProvider.cs @@ -62,6 +62,7 @@ public async Task InitializeAsync() { try { + var previousWindowToBringToForeground = IntPtr.Zero; while (true) { // First, find the game processes. This will always return at least one process, @@ -70,9 +71,13 @@ public async Task InitializeAsync() if (processes.Count == 1) { // When there is only one process, we simply bring the window to the - // foreground. + // foreground (if we didn't do it already). this.windowHandle = this.environmentInterface.FindMainWindowHandleOfProcess(processes[0]); - this.environmentInterface.BringWindowToForeground(this.windowHandle); + if (this.windowHandle != previousWindowToBringToForeground) + { + previousWindowToBringToForeground = this.windowHandle; + this.environmentInterface.BringWindowToForeground(this.windowHandle); + } // Wait a bit so that the window can go into foreground. await WaitSemaphoreInternalAsync(250, false);