Using the class to generate input events differs from posting events to the AWT event queue or AWT components in that the events are generated in the platform's native input queue. For example, Robot.mouseMove
will actually move the mouse cursor instead of just generating mouse move events.
Note that some platforms require special privileges or extensions to access low-level input control. If the current platform configuration does not allow input control, an AWTException
will be thrown when trying to construct Robot objects. For example, X-Window systems will throw the exception if the XTEST 2.2 standard extension is not supported (or not enabled) by the X server.
Applications that use Robot for purposes other than self-testing should handle these error conditions gracefully.
Platforms and desktop environments may impose restrictions or limitations on the access required to implement all functionality in the Robot class. For example:
- preventing access to the contents of any part of a desktop or Window on the desktop that is not owned by the running application.
- treating window decorations as non-owned content.
- ignoring or limiting specific requests to manipulate windows.
- ignoring or limiting specific requests for Robot generated (synthesized) events related to keyboard and mouse etc.
- requiring specific or global permissions to any access to window contents, even application owned content,or to perform even limited synthesizing of events.
- be required every time
- or persistent for the lifetime of an application,
- or persistent across multiple user desktop sessions
- be fine-grained permissions
- be associated with a specific binary application, or a class of binary applications.
- Since:
- 1.3
Constructors
- ✓public Robot() throws java.awt.AWTException
- ✓public Robot(java.awt.GraphicsDevice arg0) throws java.awt.AWTException
Methods
- ✗public java.awt.image.MultiResolutionImage createMultiResolutionScreenCapture(java.awt.Rectangle arg0)Comparing jdk-20-ga and jdk-21+35
createMultiResolutionScreenCapture
Creates an image containing pixels read from the screen. This image does not include the mouse cursor. This method can be used in case there is a scaling transform from user space to screen (device) space. Typically this means that the display is a high resolution screen, although strictly it means any case in which there is such a transform. Returns aMultiResolutionImage.For a non-scaled display, the
MultiResolutionImagewill have one image variant:- Base Image with user specified size.
For a high resolution display where there is a scaling transform, the
MultiResolutionImagewill have two image variants:- Base Image with user specified size. This is scaled from the screen.
- Native device resolution image with device size pixels.
Example:
Image nativeResImage; MultiResolutionImage mrImage = robot.createMultiResolutionScreenCapture(frame.getBounds()); List<Image> resolutionVariants = mrImage.getResolutionVariants(); if (resolutionVariants.size() > 1) { nativeResImage = resolutionVariants.get(1); } else { nativeResImage = resolutionVariants.get(0); }- Parameters:
screenRect- Rect to capture in screen coordinates- Returns:
- The captured image
- Throws:
IllegalArgumentException- ifscreenRectwidth and height are not greater than zeroSecurityException- ifreadDisplayPixelspermission is not granted, or access to the screen is denied by the desktop environment- Since:
- 9
- See Also:
- ✗public java.awt.image.BufferedImage createScreenCapture(java.awt.Rectangle arg0)Comparing jdk-20-ga and jdk-21+35
createScreenCapture
Creates an image containing pixels read from the screen. This image does not include the mouse cursor.If the desktop environment requires that permissions be granted to capture screen content, and the required permissions are not granted, then a
SecurityExceptionmay be thrown, or the contents of the returnedBufferedImageare undefined.- API Note:
- It is recommended to avoid calling this method on the AWT Event Dispatch Thread since screen capture may be a lengthy operation, particularly if acquiring permissions is needed and involves user interaction.
- Parameters:
screenRect- Rect to capture in screen coordinates- Returns:
- The captured image
- Throws:
IllegalArgumentException- ifscreenRectwidth and height are not greater than zeroSecurityException- ifreadDisplayPixelspermission is not granted, or access to the screen is denied by the desktop environment- See Also:
- ✓public void delay(int arg0)
- ✓public int getAutoDelay()
- ✗public java.awt.Color getPixelColor(int arg0, int arg1)Comparing jdk-20-ga and jdk-21+35
getPixelColor
Returns the color of a pixel at the given screen coordinates.Moved to a paragraph. If the desktop environment requires that permissions be granted to capture screen content, and the required permissions are not granted, then a
SecurityExceptionmay be thrown, or the content of the returnedColoris undefined.- API Note:
- It is recommended to avoid calling this method on the AWT Event Dispatch Thread since screen capture may be a lengthy operation, particularly if acquiring permissions is needed and involves user interaction.
- Parameters:
x- X position of pixely- Y position of pixel- Returns:
- Color of the pixel
- Throws:
SecurityException- ifreadDisplayPixelspermission is not granted, or access to the screen is denied by the desktop environment
- ✓public boolean isAutoWaitForIdle()
- ✓public void keyPress(int arg0)
- ✓public void keyRelease(int arg0)
- ✓public void mouseMove(int arg0, int arg1)
- ✓public void mousePress(int arg0)
- ✓public void mouseRelease(int arg0)
- ✓public void mouseWheel(int arg0)
- ✓public void setAutoDelay(int arg0)
- ✓public void setAutoWaitForIdle(boolean arg0)
- ✓public java.lang.String toString()
- ✓public void waitForIdle()
Summary
| Elements | Comments | Descriptions | Total | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Added | Changed | Removed | Added | Changed | Removed | Added | Changed | Removed | ||
| Robot | 3 | 3 | ||||||||
| createMultiResolutionScreenCapture(Rectangle) | 2 | 1 | 3 | |||||||
| createScreenCapture(Rectangle) | 1 | 1 | 2 | |||||||
| getPixelColor(int,int) | 4 | 1 | 5 | |||||||
| Total | 10 | 1 | 2 | 13 | ||||||