Top Description Fields Constructors Methods
javafx.scene.robot

public final Class Robot

extends Object
Class Inheritance
Imports
java.util.Objects, javafx.geometry.Point2D, .Rectangle2D, javafx.scene.image.Image, .WritableImage, javafx.scene.input.KeyCode, .MouseButton, javafx.scene.paint.Color, com.sun.glass.ui.Application, .GlassRobot, com.sun.javafx.tk.Toolkit

A Robot is used for simulating user interaction such as typing keys on the keyboard and using the mouse as well as capturing graphical information without requiring a javafx.scene.Scene instance. Robot objects must be constructed and used on the JavaFX Application Thread.
Since
11

Field Summary

Modifier and TypeField and Description
private final GlassRobot

Constructor Summary

AccessConstructor and Description
public
Robot()

Constructs a new Robot that can be used for simulating user interactions.

Method Summary

Modifier and TypeMethod and Description
public Point2D

Returns:

the current mouse (x,y) screen coordinates
getMousePosition
()

Returns the current mouse (x,y) screen coordinates as a Point2D.

public double

Returns:

the current mouse x position
getMouseX
()

Returns the current mouse x position in screen coordinates.

public double

Returns:

the current mouse y position
getMouseY
()

Returns the current mouse y position in screen coordinates.

public Color

Returns:

the pixel color at the specified screen coordinates
getPixelColor
(double
the x coordinate to get the pixel color from
x
,
double
the y coordinate to get the pixel color from
y
)

Returns the Color of the pixel at the screen coordinates relative to the primary screen specified by location.

public Color

Returns:

the pixel color at the specified screen coordinates
getPixelColor
(Point2D
the (x,y) coordinates to get the pixel color from
location
)

Returns the Color of the pixel at the screen coordinates relative to the primary screen specified by location.

public WritableImage

Returns:

the screen capture of the specified region as a WritableImage
getScreenCapture
(WritableImage
either null or a WritableImage that will be used to place the screen capture in
image
,
double
the starting x-position of the rectangular area to capture
x
,
double
the starting y-position of the rectangular area to capture
y
,
double
the width of the rectangular area to capture
width
,
double
the height of the rectangular area to capture
height
,
boolean
If true, the returned Image will be scaled to fit the request dimensions (if necessary). Otherwise, the size of the returned image will depend on the output scale (DPI) of the primary screen.
scaleToFit
)

Returns a WritableImage containing the specified rectangular area relative to the primary screen.

public WritableImage

Returns:

the screen capture of the specified region as a WritableImage
getScreenCapture
(WritableImage
either null or a WritableImage that will be used to place the screen capture in
image
,
double
the starting x-position of the rectangular area to capture
x
,
double
the starting y-position of the rectangular area to capture
y
,
double
the width of the rectangular area to capture
width
,
double
the height of the rectangular area to capture
height
)

Returns a WritableImage containing the specified rectangular area relative to the primary screen.

public WritableImage

Returns:

the screen capture of the specified region as a WritableImage
getScreenCapture
(WritableImage
either null or a WritableImage that will be used to place the screen capture in
image
,
Rectangle2D
the rectangular area of the screen to capture
region
)

Returns a WritableImage containing the specified rectangular area relative to the primary screen.

public WritableImage

Returns:

the screen capture of the specified region as a WritableImage
getScreenCapture
(WritableImage
either null or a WritableImage that will be used to place the screen capture in
image
,
Rectangle2D
the rectangular area of the screen to capture
region
,
boolean
if true, the returned Image will be scaled to fit the request dimensions (if necessary). Otherwise, the size of the returned image will depend on the output scale (DPI) of the primary screen.
scaleToFit
)

Returns a WritableImage containing the specified rectangular area relative to the primary screen.

public void
keyPress(KeyCode
the key to press
keyCode
)

Presses the specified KeyCode key.

public void
keyRelease(KeyCode
the key to release
keyCode
)

Releases the specified KeyCode key.

public void
keyType(KeyCode
the key to type
keyCode
)

Types the specified KeyCode key.

public void
mouseClick(MouseButton...
the mouse buttons to click
buttons
)

Clicks the specified MouseButtons.

public void
mouseMove(double
screen coordinate x to move the mouse to
x
,
double
screen coordinate y to move the mouse to
y
)

Moves the mouse to the specified (x,y) screen coordinates relative to the primary screen.

public final void
mouseMove(Point2D
the (x,y) coordinates to move the mouse to
location
)

Moves the mouse to the (x,y) screen coordinates, relative to the primary screen, specified by the given location.

public void
mousePress(MouseButton...
the mouse buttons to press
buttons
)

Presses the specified MouseButtons.

public void
mouseRelease(MouseButton...
the mouse buttons to release
buttons
)

Releases the specified MouseButtons.

public void
mouseWheel(int
the (signed) amount of clicks to scroll the wheel
wheelAmt
)

Scrolls the mouse wheel by the specified amount of wheel clicks.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

peerback to summary
private final GlassRobot peer

Constructor Detail

Robotback to summary
public Robot()

Constructs a new Robot that can be used for simulating user interactions.

Exceptions
IllegalStateException:
if this object is constructed on a thread other than the JavaFX Application Thread.

Method Detail

getMousePositionback to summary
public Point2D getMousePosition()

Returns the current mouse (x,y) screen coordinates as a Point2D.

Returns:Point2D

the current mouse (x,y) screen coordinates

Exceptions
IllegalStateException:
if this method is called on a thread other than the JavaFX Application Thread.
getMouseXback to summary
public double getMouseX()

Returns the current mouse x position in screen coordinates.

Returns:double

the current mouse x position

Exceptions
IllegalStateException:
if this method is called on a thread other than the JavaFX Application Thread.
getMouseYback to summary
public double getMouseY()

Returns the current mouse y position in screen coordinates.

Returns:double

the current mouse y position

Exceptions
IllegalStateException:
if this method is called on a thread other than the JavaFX Application Thread.
getPixelColorback to summary
public Color getPixelColor(double x, double y)

Returns the Color of the pixel at the screen coordinates relative to the primary screen specified by location. Regardless of the scale of the screen (javafx.stage.Screen#getOutputScaleX(), javafx.stage.Screen#getOutputScaleY()), this method only samples a single pixel. For example, on a HiDPI screen with output scale 2, the screen unit at the point (x,y) may have 4 pixels. In this case the color returned is the color of the top, left pixel. Color values are not averaged when a screen unit is made up of more than one pixel.

Parameters
x:double

the x coordinate to get the pixel color from

y:double

the y coordinate to get the pixel color from

Returns:Color

the pixel color at the specified screen coordinates

Exceptions
IllegalStateException:
if this method is called on a thread other than the JavaFX Application Thread.
getPixelColorback to summary
public Color getPixelColor(Point2D location)

Returns the Color of the pixel at the screen coordinates relative to the primary screen specified by location. Regardless of the scale of the screen (javafx.stage.Screen#getOutputScaleX(), javafx.stage.Screen#getOutputScaleY()), this method only samples a single pixel. For example, on a HiDPI screen with output scale 2, the screen unit at the point (x,y) may have 4 pixels. In this case the color returned is the color of the top, left pixel. Color values are not averaged when a screen unit is made up of more than one pixel.

Parameters
location:Point2D

the (x,y) coordinates to get the pixel color from

Returns:Color

the pixel color at the specified screen coordinates

Exceptions
NullPointerException:
if the given location is null
IllegalStateException:
if this method is called on a thread other than the JavaFX Application Thread.
getScreenCaptureback to summary
public WritableImage getScreenCapture(WritableImage image, double x, double y, double width, double height, boolean scaleToFit)

Returns a WritableImage containing the specified rectangular area relative to the primary screen. If the given image is null, or if the given image is not the required size, a new WritableImage will be created and returned. Otherwise, the given image is re-used.

If the scaleToFit argument is false, the returned Image object dimensions may differ from the requested width and height depending on how many physical pixels the area occupies on the screen. For example, in HiDPI mode on the Mac (aka Retina display) the pixels are doubled, and thus a screen capture of an area of size (10x10) pixels will result in an Image with dimensions (20x20). Calling code should use the returned image's Image#getWidth() and Image#getHeight() methods to determine the actual image size.

If scaleToFit is true, the returned Image is of the requested size. Note that in this case the image will be scaled in order to fit to the requested dimensions if necessary, such as when running on a HiDPI display.

Parameters
image:WritableImage

either null or a WritableImage that will be used to place the screen capture in

x:double

the starting x-position of the rectangular area to capture

y:double

the starting y-position of the rectangular area to capture

width:double

the width of the rectangular area to capture

height:double

the height of the rectangular area to capture

scaleToFit:boolean

If true, the returned Image will be scaled to fit the request dimensions (if necessary). Otherwise, the size of the returned image will depend on the output scale (DPI) of the primary screen.

Returns:WritableImage

the screen capture of the specified region as a WritableImage

Exceptions
IllegalStateException:
if this method is called on a thread other than the JavaFX Application Thread.
getScreenCaptureback to summary
public WritableImage getScreenCapture(WritableImage image, double x, double y, double width, double height)

Returns a WritableImage containing the specified rectangular area relative to the primary screen. If the given image is null, or if the given image is not the required size, a new WritableImage will be created and returned. Otherwise, the given image is re-used.

Implementation Specification

This method is equivalent to calling getScreenCapture(x, y, width, height, true), that is, this method scales the image to fit the requested size.

Parameters
image:WritableImage

either null or a WritableImage that will be used to place the screen capture in

x:double

the starting x-position of the rectangular area to capture

y:double

the starting y-position of the rectangular area to capture

width:double

the width of the rectangular area to capture

height:double

the height of the rectangular area to capture

Returns:WritableImage

the screen capture of the specified region as a WritableImage

Exceptions
IllegalStateException:
if this method is called on a thread other than the JavaFX Application Thread.
getScreenCaptureback to summary
public WritableImage getScreenCapture(WritableImage image, Rectangle2D region)

Returns a WritableImage containing the specified rectangular area relative to the primary screen. If the given image is null, or if the given image is not the required size, a new WritableImage will be created and returned. Otherwise, the given image is re-used.

Implementation Specification

This method is equivalent to calling getScreenCapture(image, region, true), that is, this method scales the image to fit the requested size.

Parameters
image:WritableImage

either null or a WritableImage that will be used to place the screen capture in

region:Rectangle2D

the rectangular area of the screen to capture

Returns:WritableImage

the screen capture of the specified region as a WritableImage

Exceptions
IllegalStateException:
if this method is called on a thread other than the JavaFX Application Thread.
NullPointerException:
if region is null.
getScreenCaptureback to summary
public WritableImage getScreenCapture(WritableImage image, Rectangle2D region, boolean scaleToFit)

Returns a WritableImage containing the specified rectangular area relative to the primary screen. If the given image is null, or if the given image is not the required size, a new WritableImage will be created and returned. Otherwise, the given image is re-used.

If the scaleToFit argument is false, the returned Image object dimensions may differ from the requested width and height depending on how many physical pixels the area occupies on the screen. For example, in HiDPI mode on the Mac (aka Retina display) the pixels are doubled, and thus a screen capture of an area of size (10x10) pixels will result in an Image with dimensions (20x20). Calling code should use the returned image's Image#getWidth() and Image#getHeight() methods to determine the actual image size.

If scaleToFit is true, the returned Image is of the requested size. Note that in this case the image will be scaled in order to fit to the requested dimensions if necessary, such as when running on a HiDPI display.

Parameters
image:WritableImage

either null or a WritableImage that will be used to place the screen capture in

region:Rectangle2D

the rectangular area of the screen to capture

scaleToFit:boolean

if true, the returned Image will be scaled to fit the request dimensions (if necessary). Otherwise, the size of the returned image will depend on the output scale (DPI) of the primary screen.

Returns:WritableImage

the screen capture of the specified region as a WritableImage

Exceptions
IllegalStateException:
if this method is called on a thread other than the JavaFX Application Thread.
NullPointerException:
if region is null.
keyPressback to summary
public void keyPress(KeyCode keyCode)

Presses the specified KeyCode key.

Parameters
keyCode:KeyCode

the key to press

Exceptions
IllegalStateException:
if this method is called on a thread other than the JavaFX Application Thread.
NullPointerException:
if keyCode is null.
keyReleaseback to summary
public void keyRelease(KeyCode keyCode)

Releases the specified KeyCode key.

Parameters
keyCode:KeyCode

the key to release

Exceptions
IllegalStateException:
if this method is called on a thread other than the JavaFX Application Thread.
NullPointerException:
if keyCode is null.
keyTypeback to summary
public void keyType(KeyCode keyCode)

Types the specified KeyCode key.

Implementation Specification

This is a convenience method that is equivalent to calling keyPress(KeyCode) followed by keyRelease(KeyCode).

Parameters
keyCode:KeyCode

the key to type

Exceptions
IllegalStateException:
if this method is called on a thread other than the JavaFX Application Thread.
NullPointerException:
if keyCode is null.
mouseClickback to summary
public void mouseClick(MouseButton... buttons)

Clicks the specified MouseButtons.

Implementation Specification

This is a convenience method that is equivalent to calling mousePress(MouseButton...) followed by mouseRelease(MouseButton...).

Parameters
buttons:MouseButton[]

the mouse buttons to click

Exceptions
IllegalStateException:
if this method is called on a thread other than the JavaFX Application Thread.
NullPointerException:
if buttons is null.
mouseMoveback to summary
public void mouseMove(double x, double y)

Moves the mouse to the specified (x,y) screen coordinates relative to the primary screen.

Parameters
x:double

screen coordinate x to move the mouse to

y:double

screen coordinate y to move the mouse to

Exceptions
IllegalStateException:
if this method is called on a thread other than the JavaFX Application Thread.
mouseMoveback to summary
public final void mouseMove(Point2D location)

Moves the mouse to the (x,y) screen coordinates, relative to the primary screen, specified by the given location.

Parameters
location:Point2D

the (x,y) coordinates to move the mouse to

Exceptions
IllegalStateException:
if this method is called on a thread other than the JavaFX Application Thread.
NullPointerException:
if location is null.
mousePressback to summary
public void mousePress(MouseButton... buttons)

Presses the specified MouseButtons.

Parameters
buttons:MouseButton[]

the mouse buttons to press

Exceptions
IllegalStateException:
if this method is called on a thread other than the JavaFX Application Thread.
NullPointerException:
if buttons is null.
mouseReleaseback to summary
public void mouseRelease(MouseButton... buttons)

Releases the specified MouseButtons.

Parameters
buttons:MouseButton[]

the mouse buttons to release

Exceptions
IllegalStateException:
if this method is called on a thread other than the JavaFX Application Thread.
NullPointerException:
if buttons is null.
mouseWheelback to summary
public void mouseWheel(int wheelAmt)

Scrolls the mouse wheel by the specified amount of wheel clicks. A positive wheelAmt scrolls the wheel towards the user (down) whereas negative amounts scrolls the wheel away from the user (up).

Parameters
wheelAmt:int

the (signed) amount of clicks to scroll the wheel

Exceptions
IllegalStateException:
if this method is called on a thread other than the JavaFX Application Thread.