This question is very similar to this one (Detect active window changed using C# without polling), and the code on that accepted answer works fine with a Windows Forms Application, but no way with a Console Application.
¿How can I detect that active window has changed without doing infinite iterations (or any type of polling) with a Console Application?
Thanks in advance.
It can be changed to run as a console application with a few changes. Here is a working code.