A managed wrapper over SetWinEventHook and UnhookWinEvent.
To install with NuGet use the following command in the Packet Manager Console:
Install-Package WinEventHook
Prints all events to the console:
using var hook = new WindowEventHook();
hook.EventReceived += (s, e) =>
Console.WriteLine(Enum.GetName(typeof(WindowEvent), e.EventType));
hook.HookGlobal();
Console.Read();
Note: Your application needs a message loop to receive events.