Which event identifies if a user is switching applications on MacOS?

I was wondering if there is a way to identify when a user is switching applications on MacOS. Any pointers?

The frontmostApplication property of the NSWorkspace class can be observed with key-value observing (KVO).

Which event identifies if a user is switching applications on MacOS?
 
 
Q