I want to pause my game (written in Java Swing), when the player switches to another application.
But I did not find a way to detect this switch. window.isActive()
only works for multiple windows within one Java application. But it does return true
, when a different application has the focus.
The same is true for the KeyboardFocusManager
, it returns the window of my application that had the focus before the focus was given to another application.