I am trying to capture screen in mac os ventura using java.awt.robort but it captures the desktop image every time but not the image of current application running. As shown in https://i.stack.imgur.com/KABpT.png. Also it does not captures the second screen attached to laptop.
Rectangle screenRect = new Rectangle(0, 0, 0, 0);
for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
screenRect = screenRect.union(gd.getDefaultConfiguration().getBounds());
}
BufferedImage screenFullImage = new Robot().createScreenCapture(screenRect);
/*
* final BufferedImage screenFullImage = new Robot() .createScreenCapture(new
* Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
*/
ImageIO.write(screenFullImage, AppConstants.JPG_FORMAT, new File(imageFilePath.toString()));