On appactive
From Scriptwiki
The on APPACTIVE events trigger when mIRC's active status changes.
on <level>:APPACTIVE:<commands>
This event triggers whenever mIRC's active status has changed. The $appactive identifier returns $true if mIRC is active, or $false if it isn't.
Example
on *:APPACTIVE: { echo -a mIRC active status: $appactive }
This example triggers whenever mIRC's active stats has changed and echos the new status to the active window.
See Also
Take a look at the On active event to react whenever mIRC's active window has changed.