With a system-wide mouse hook.
That's more than just a little bit of API, it involves DLLs and callbacks.