For several apps, Claveilleur can use AXFocusedWindowChanged to see if they are switched to, but it doesn't seem to know when they are switched away from.
Some examples include:
com.apple.notificationcenterui
com.apple.controlcenter
The current workaround is simply to first switch to another app that doesn't have this issue, and after that everything will work as intended again.