System.onDeactivate

Function/Meaning
When the application becomes inactive
Type
System Class Properties
Explanation

Represents an event function that is called when the application becomes inactive.
If null is specified, the function will not be called.
Unlike regular event handlers, if you want to receive this event, set this property to the function you want to call.
Window.onDeactivate is fired when each window in the same application is deactivated, but this event is fired when the main window is deactivated.
Note that this event can also occur if the main window is already inactive (there is no guarantee that it will occur completely onActivate → onDeactivate → onActivate → ……).

Reference
System.onActivate
Window.onActivate
Window.onDeactivate