Using Java, the robot class enables software screenshots, as follows:
Package Test;import Java.awt.awtexception;import Java.awt.displaymode;import java.awt.graphicsdevice;import Java.awt.graphicsenvironment;import Java.awt.image;import Java.awt.menuitem;import Java.awt.PopupMenu;import Java.awt.rectangle;import Java.awt.robot;import Java.awt.systemtray;import Java.awt.trayicon;import Java.awt.event.actionevent;import Java.awt.event.actionlistener;import Java.awt.event.keyevent;import Java.awt.event.mouseevent;import Java.awt.image.bufferedimage;import Java.io.file;import Java.io.filenotfoundexception;import Java.io.fileoutputstream;import Java.io.ioexception;import java.util.Date; Import Javax.imageio.imageio;public class Testrobot {private static Robot bt;private static GraphicsDevice gd;static {Gra Phicsenvironment ge = graphicsenvironment.getlocalgraphicsenvironment (); graphicsdevice[] GS = ge.getscreendevices (); gd = gs[0];try {bt = new Robot (GD);} catch (Awtexception e) {E.printstacktrace ();}} public static void Test1 () {try {displaymode mode = Gd.getdisPlayMode (); int width = mode.getwidth (); int height = mode.getheight (); System.out.println (width + "x" + height); BufferedImage img = bt.createscreencapture (new Rectangle (width,height));D ate date = new Date ();// The path below is used to save the path and name of the screenshot image FileOutputStream Fos = new FileOutputStream ("/home/qcq/" + date.gettime () + ". jpg"); Imageio.write ( IMG, "JPEG", FOS); Fos.close ();} catch (FileNotFoundException e) {e.printstacktrace ();} catch (IOException e) {e.printstacktrace ()}} public static void Main (string[] args) {Systemtray tray = Systemtray.getsystemtray ();//create the traytry {//here requires the icon for the given pallet. Image image = Imageio.read (new File ("src/1.jpg")); PopupMenu menu = new PopupMenu (); MenuItem m1 = new MenuItem ("screenshot"); MenuItem M0 = new MenuItem ("Exit"); Menu.add (M1); Menu.add (M0); TrayIcon TrayIcon = new TrayIcon (image, "screenshot", menu); Tray.add (TrayIcon); M1.addactionlistener (new ActionListener () {@ overridepublic void actionperformed (ActionEvent e) {test1 ();}}); M0.addactionlistener (new ActionListener () {@Overridepublic void actionPerformed (ActionEvent e) {system.exit (0);}}); /Automatically press the keyboard to display the desktop (Windows). Linux fails and can be used to intercept the desktop. Bt.keypress (keyevent.vk_windows); bt.keypress (keyevent.vk_d); Bt.keyrelease (keyevent.vk_windows); Bt.keyRelease ( Keyevent.vk_d);} catch (IOException e) {e.printstacktrace ();} catch (Awtexception e) {e.printstacktrace ()}}}
Java Code screenshot