7

Image shows what getDisplayMedia() does

I want to show user, all the current opened applications/windows (like that of alt+tab) using java. In javaScript we can do this by Media Devices interface getDisplayMedia(). I want to implement similar feature using java. Is there any way to do this using JNA, or something else.

jhpratt
  • 6,841
  • 16
  • 40
  • 50
Nirman
  • 103
  • 2
  • 11
  • 1
    Check out the following post: https://stackoverflow.com/questions/4433994/java-window-image/4682351#4682351 Apparently the window cannot be minimized for the example code to work properly, but you could work around that. Regardless, it will still screenshot all focused and unfocused windows. – mperic Jul 25 '19 at 19:02

1 Answers1

2

The method I'm sharing does the trick of pulling up the alt+tab menu using Java Robot and letting it close after a delay (It switches the window as well). Hope this helps!

public static void alt_tab() {
    Robot robot;

    try {
        robot = new Robot();
        robot.keyPress(KeyEvent.VK_ALT);
        robot.keyPress(KeyEvent.VK_TAB);
        robot.keyRelease(KeyEvent.VK_TAB);
        robot.delay(5000);
        robot.keyRelease(KeyEvent.VK_ALT);
    } catch (AWTException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

Cheers!

JDevr
  • 46
  • 2
  • I tried this, but is not reliable as if the user does not click on one of the windows he might get the wrong output. i want to hold the screen as long as user does not click on one of the windows given. – Nirman Jul 30 '19 at 06:04
  • You would need to replace the delay with an MouseListener in your code for that function. – JDevr Jul 30 '19 at 13:40
  • Use below link to resolve the issue https://stackoverflow.com/questions/14549526/alttab-using-java-robot – Akash Jul 31 '19 at 07:47
  • Thanks Jdevr and Akash for your help... I will try this both methods. – Nirman Aug 02 '19 at 06:50