java.awt
Class Robot

java.lang.Object
  |
  +--java.awt.Robot

public class Robot
extends Object

Unsafe:


Field Summary
private  int autoDelay
           
private static AWTPermission createRobotPermission
           
private  boolean isAutoWaitForIdle
           
private static int LEGAL_BUTTON_MASK
           
private static int MAX_DELAY
           
private  java.awt.peer.RobotPeer peer
           
private static AWTPermission readDisplayPixelsPermission
           
private  java.awt.image.DirectColorModel screenCapCM
           
 
Constructor Summary
Robot()
          Enabled: Constructs a Robot object in the coordinate system of the primary screen.
Robot(GraphicsDevice screen)
          Enabled: Creates a Robot for the given screen device.
 
Method Summary
private  void afterEvent()
           
private  void autoDelay()
           
private  void autoWaitForIdle()
           
private  void checkButtonsArgument(int buttons)
           
private  void checkDelayArgument(int ms)
           
private  void checkIsScreenDevice(GraphicsDevice device)
           
private  void checkKeycodeArgument(int keycode)
           
private  void checkNotDispatchThread()
           
private  void checkRobotAllowed()
           
private static void checkScreenCaptureAllowed()
           
private static void checkValidRect(Rectangle rect)
           
 java.awt.image.BufferedImage createScreenCapture(Rectangle screenRect)
          Enabled: Creates an image containing pixels read from the screen.
 void delay(int ms)
          Enabled: Sleeps for the specified time.
 int getAutoDelay()
          Enabled: Returns the number of milliseconds this Robot sleeps after generating an event.
 Color getPixelColor(int x, int y)
          Enabled: Returns the color of a pixel at the given screen coordinates.
private  void init(GraphicsDevice screen)
           
 boolean isAutoWaitForIdle()
          Suppressed: Returns whether this Robot automatically invokes waitForIdle after generating an event.
 void keyPress(int keycode)
          Enabled: Presses a given key.
 void keyRelease(int keycode)
          Enabled: Releases a given key.
 void mouseMove(int x, int y)
          Enabled: Moves mouse pointer to given screen coordinates.
 void mousePress(int buttons)
          Enabled: Presses one or more mouse buttons.
 void mouseRelease(int buttons)
          Enabled: Releases one or more mouse buttons.
 void mouseWheel(int wheelAmt)
          Enabled: Rotates the scroll wheel on wheel-equipped mice.
 void setAutoDelay(int ms)
          Suppressed: Sets the number of milliseconds this Robot sleeps after generating an event.
 void setAutoWaitForIdle(boolean isOn)
          Suppressed: Sets whether this Robot automatically invokes waitForIdle after generating an event.
 String toString()
          Suppressed: Returns a string representation of this Robot.
 void waitForIdle()
          Enabled: Waits until all events currently on the event queue have been processed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_DELAY

private static final int MAX_DELAY

peer

private java.awt.peer.RobotPeer peer

isAutoWaitForIdle

private boolean isAutoWaitForIdle

autoDelay

private int autoDelay

readDisplayPixelsPermission

private static AWTPermission readDisplayPixelsPermission

createRobotPermission

private static AWTPermission createRobotPermission

LEGAL_BUTTON_MASK

private static final int LEGAL_BUTTON_MASK

screenCapCM

private java.awt.image.DirectColorModel screenCapCM
Constructor Detail

Robot

public Robot()
      throws AWTException
Enabled: Constructs a Robot object in the coordinate system of the primary screen.

Throws:
AWTException - if the platform configuration does not allow low-level input control. This exception is always thrown when GraphicsEnvironment.isHeadless() returns true
SecurityException - if createRobot permission is not granted
See Also:
java.awt.GraphicsEnvironment#isHeadless, SecurityManager.checkPermission(java.security.Permission), AWTPermission

Robot

public Robot(GraphicsDevice screen)
      throws AWTException
Enabled: Creates a Robot for the given screen device. Coordinates passed to Robot method calls like mouseMove and createScreenCapture will be interpreted as being in the same coordinate system as the specified screen. Note that depending on the platform configuration, multiple screens may either: This constructor is meant for the latter case.

If screen devices are reconfigured such that the coordinate system is affected, the behavior of existing Robot objects is undefined.

Parameters:
screen - A screen GraphicsDevice indicating the coordinate system the Robot will operate in.
Throws:
AWTException - if the platform configuration does not allow low-level input control. This exception is always thrown when GraphicsEnvironment.isHeadless() returns true.
IllegalArgumentException - if screen is not a screen GraphicsDevice.
SecurityException - if createRobot permission is not granted
See Also:
java.awt.GraphicsEnvironment#isHeadless, GraphicsDevice, SecurityManager.checkPermission(java.security.Permission), AWTPermission
Method Detail

init

private void init(GraphicsDevice screen)
           throws AWTException
AWTException

checkRobotAllowed

private void checkRobotAllowed()

checkIsScreenDevice

private void checkIsScreenDevice(GraphicsDevice device)

mouseMove

public void mouseMove(int x,
                      int y)
Enabled: Moves mouse pointer to given screen coordinates.

Parameters:
x - X position
y - Y position

mousePress

public void mousePress(int buttons)
Enabled: Presses one or more mouse buttons.

Parameters:
buttons - the Button mask; a combination of one or more of these flags:
  • InputEvent.BUTTON1_MASK
  • InputEvent.BUTTON2_MASK
  • InputEvent.BUTTON3_MASK
Throws:
IllegalArgumentException - if the button mask is not a valid combination

mouseRelease

public void mouseRelease(int buttons)
Enabled: Releases one or more mouse buttons.

Parameters:
buttons - the Button mask; a combination of one or more of these flags:
  • InputEvent.BUTTON1_MASK
  • InputEvent.BUTTON2_MASK
  • InputEvent.BUTTON3_MASK
Throws:
IllegalArgumentException - if the button mask is not a valid combination

checkButtonsArgument

private void checkButtonsArgument(int buttons)

mouseWheel

public void mouseWheel(int wheelAmt)
Enabled: Rotates the scroll wheel on wheel-equipped mice.

Parameters:
wheelAmt - number of "notches" to move the mouse wheel Negative values indicate movement up/away from the user, positive values indicate movement down/towards the user.
Since:
1.4

keyPress

public void keyPress(int keycode)
Enabled: Presses a given key.

Key codes that have more than one physical key associated with them (e.g. KeyEvent.VK_SHIFT could mean either the left or right shift key) will map to the left key.

Throws:
IllegalArgumentException - if keycode is not a valid key
See Also:
java.awt.event.KeyEvent

keyRelease

public void keyRelease(int keycode)
Enabled: Releases a given key.

Key codes that have more than one physical key associated with them (e.g. KeyEvent.VK_SHIFT could mean either the left or right shift key) will map to the left key.

Throws:
IllegalArgumentException - if keycode is not a valid key
See Also:
java.awt.event.KeyEvent

checkKeycodeArgument

private void checkKeycodeArgument(int keycode)

getPixelColor

public Color getPixelColor(int x,
                           int y)
Enabled: Returns the color of a pixel at the given screen coordinates.

Parameters:
x - X position of pixel
y - Y position of pixel
Returns:
Color of the pixel

createScreenCapture

public java.awt.image.BufferedImage createScreenCapture(Rectangle screenRect)
Enabled: Creates an image containing pixels read from the screen.

Parameters:
screenRect - Rect to capture in screen coordinates
Returns:
The captured image
Throws:
IllegalArgumentException - if screenRect width and height are not greater than zero
SecurityException - if readDisplayPixels permission is not granted
See Also:
SecurityManager.checkPermission(java.security.Permission), AWTPermission

checkValidRect

private static void checkValidRect(Rectangle rect)

checkScreenCaptureAllowed

private static void checkScreenCaptureAllowed()

afterEvent

private void afterEvent()

isAutoWaitForIdle

public boolean isAutoWaitForIdle()
Suppressed: Returns whether this Robot automatically invokes waitForIdle after generating an event.

Returns:
Whether waitForIdle is automatically called

setAutoWaitForIdle

public void setAutoWaitForIdle(boolean isOn)
Suppressed: Sets whether this Robot automatically invokes waitForIdle after generating an event.

Parameters:
isOn - Whether waitForIdle is automatically invoked

autoWaitForIdle

private void autoWaitForIdle()

getAutoDelay

public int getAutoDelay()
Enabled: Returns the number of milliseconds this Robot sleeps after generating an event.


setAutoDelay

public void setAutoDelay(int ms)
Suppressed: Sets the number of milliseconds this Robot sleeps after generating an event.

Throws:
IllegalArgumentException - If ms is not between 0 and 60,000 milliseconds inclusive

autoDelay

private void autoDelay()

delay

public void delay(int ms)
Enabled: Sleeps for the specified time. To catch any InterruptedExceptions that occur, Thread.sleep() may be used instead.

Parameters:
ms - time to sleep in milliseconds
Throws:
IllegalArgumentException - if ms is not between 0 and 60,000 milliseconds inclusive
See Also:
java.lang.Thread#sleep

checkDelayArgument

private void checkDelayArgument(int ms)

waitForIdle

public void waitForIdle()
Enabled: Waits until all events currently on the event queue have been processed.

Throws:
IllegalThreadStateException - if called on the AWT event dispatching thread

checkNotDispatchThread

private void checkNotDispatchThread()

toString

public String toString()
Suppressed: Returns a string representation of this Robot.

Overrides:
toString in class Object
Returns:
the string representation.


comments?