I'm trying to bring a Windows console application to the foreground using
SetForegroundWindow(handle);
ShowWindow(handle, (int)ShowWindowCommands.Show);
It's all working fine but after bringing the window to the foreground I want the user to confirm by pressing the enter key. But unfortunately the focus is not actually in the application but on it. So when pressing enter nothing will happen.
How can I set the focus in the console application to be able to hit enter straight away?
Here's my code:
SetForegroundWindow(handle);
ShowWindow(handle, (int)ShowWindowCommands.Show);
Console.WriteLine("Please press ENTER to confirm...");
if (Console.ReadKey().Key == ConsoleKey.Enter)
{
// do stuff
}
Please don't just ask why...