Using JFrame focus (lost) to stop screen recording?

In my Swing app, I use a custom module to record screencasts.

However, I hung up a bit to stop recording. Right now I am checking if the user still wants to record (which means that they did not click the stop button), and if the application is still open (closing the application causes the recording to stop gracefully).

The problem is that the recording will continue if the application is downloaded for other applications or minimized, which will result in the recording of "garbage". I need the recording to stop when the application is no longer “on top” of the screen. Using application focus does not seem to work due to other dialogs and things that appear.

Suggestions?

+3
source share
1 answer

You can try adding a WindowListener and overriding the windowDeactivated () event, which should be raised when the frame is no longer the "active window" according to the operating system.

UPDATE:

, (, ), WindowListener :

    public void windowDeactivated(WindowEvent e) {
        if(e.getOppositeWindow() == null){
            // will be null when another application window gets activated, stop recording
        }
        for(Window w : appFrame.getOwnedWindows()){
            if(w.equals(e.getOppositeWindow())){
                // one of the windows owned by the frame is active, don't stop recording
            }
        }

    }

, /.

+6

Source: https://habr.com/ru/post/1725720/


All Articles