Methods Summary |
---|
private void | afterEvent()
autoWaitForIdle();
autoDelay();
|
private void | autoDelay()
delay(autoDelay);
|
private void | autoWaitForIdle()
if (isAutoWaitForIdle) {
waitForIdle();
}
|
private void | checkButtonsArgument(int buttons)
if ( (buttons|LEGAL_BUTTON_MASK) != LEGAL_BUTTON_MASK ) {
throw new IllegalArgumentException("Invalid combination of button flags");
}
|
private void | checkDelayArgument(int ms)
if (ms < 0 || ms > MAX_DELAY) {
throw new IllegalArgumentException("Delay must be to 0 to 60,000ms");
}
|
private void | checkIsScreenDevice(java.awt.GraphicsDevice device)
if (device == null || device.getType() != GraphicsDevice.TYPE_RASTER_SCREEN) {
throw new IllegalArgumentException("not a valid screen device");
}
|
private void | checkKeycodeArgument(int keycode)
// rather than build a big table or switch statement here, we'll
// just check that the key isn't VK_UNDEFINED and assume that the
// peer implementations will throw an exception for other bogus
// values e.g. -1, 999999
if (keycode == KeyEvent.VK_UNDEFINED) {
throw new IllegalArgumentException("Invalid key code");
}
|
private void | checkNotDispatchThread()
if (EventQueue.isDispatchThread()) {
throw new IllegalThreadStateException("Cannot call method from the event dispatcher thread");
}
|
private void | checkRobotAllowed()
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(SecurityConstants.CREATE_ROBOT_PERMISSION);
}
|
private static void | checkScreenCaptureAllowed()
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(
SecurityConstants.READ_DISPLAY_PIXELS_PERMISSION);
}
|
private static void | checkValidRect(java.awt.Rectangle rect)
if (rect.width <= 0 || rect.height <= 0) {
throw new IllegalArgumentException("Rectangle width and height must be > 0");
}
|
public synchronized java.awt.image.BufferedImage | createScreenCapture(java.awt.Rectangle screenRect)Creates an image containing pixels read from the screen. This image does
not include the mouse cursor.
checkScreenCaptureAllowed();
checkValidRect(screenRect);
BufferedImage image;
DataBufferInt buffer;
WritableRaster raster;
if (screenCapCM == null) {
/*
* Fix for 4285201
* Create a DirectColorModel equivalent to the default RGB ColorModel,
* except with no Alpha component.
*/
screenCapCM = new DirectColorModel(24,
/* red mask */ 0x00FF0000,
/* green mask */ 0x0000FF00,
/* blue mask */ 0x000000FF);
}
int pixels[];
int[] bandmasks = new int[3];
pixels = peer.getRGBPixels(screenRect);
buffer = new DataBufferInt(pixels, pixels.length);
bandmasks[0] = screenCapCM.getRedMask();
bandmasks[1] = screenCapCM.getGreenMask();
bandmasks[2] = screenCapCM.getBlueMask();
raster = Raster.createPackedRaster(buffer, screenRect.width, screenRect.height, screenRect.width, bandmasks, null);
image = new BufferedImage(screenCapCM, raster, false, null);
return image;
|
public synchronized void | delay(int ms)Sleeps for the specified time.
To catch any InterruptedException s that occur,
Thread.sleep() may be used instead.
checkDelayArgument(ms);
try {
Thread.sleep(ms);
} catch(InterruptedException ite) {
ite.printStackTrace();
}
|
public synchronized int | getAutoDelay()Returns the number of milliseconds this Robot sleeps after generating an event.
return autoDelay;
|
public synchronized java.awt.Color | getPixelColor(int x, int y)Returns the color of a pixel at the given screen coordinates.
Color color = new Color(peer.getRGBPixel(x,y));
return color;
|
private void | init(java.awt.GraphicsDevice screen)
checkRobotAllowed();
Toolkit toolkit = Toolkit.getDefaultToolkit();
if (toolkit instanceof ComponentFactory) {
peer = ((ComponentFactory)toolkit).createRobot(this, screen);
}
|
public synchronized boolean | isAutoWaitForIdle()Returns whether this Robot automatically invokes waitForIdle
after generating an event.
return isAutoWaitForIdle;
|
public synchronized void | keyPress(int keycode)Presses a given key. The key should be released using the
keyRelease method.
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.
checkKeycodeArgument(keycode);
peer.keyPress(keycode);
afterEvent();
|
public synchronized void | keyRelease(int keycode)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.
checkKeycodeArgument(keycode);
peer.keyRelease(keycode);
afterEvent();
|
public synchronized void | mouseMove(int x, int y)Moves mouse pointer to given screen coordinates.
peer.mouseMove(x,y);
afterEvent();
|
public synchronized void | mousePress(int buttons)Presses one or more mouse buttons. The mouse buttons should
be released using the mouseRelease method.
checkButtonsArgument(buttons);
peer.mousePress(buttons);
afterEvent();
|
public synchronized void | mouseRelease(int buttons)Releases one or more mouse buttons.
checkButtonsArgument(buttons);
peer.mouseRelease(buttons);
afterEvent();
|
public synchronized void | mouseWheel(int wheelAmt)Rotates the scroll wheel on wheel-equipped mice.
peer.mouseWheel(wheelAmt);
afterEvent();
|
public synchronized void | setAutoDelay(int ms)Sets the number of milliseconds this Robot sleeps after generating an event.
checkDelayArgument(ms);
autoDelay = ms;
|
public synchronized void | setAutoWaitForIdle(boolean isOn)Sets whether this Robot automatically invokes waitForIdle
after generating an event.
isAutoWaitForIdle = isOn;
|
public synchronized java.lang.String | toString()Returns a string representation of this Robot.
String params = "autoDelay = "+getAutoDelay()+", "+"autoWaitForIdle = "+isAutoWaitForIdle();
return getClass().getName() + "[ " + params + " ]";
|
public synchronized void | waitForIdle()Waits until all events currently on the event queue have been processed.
checkNotDispatchThread();
// post a dummy event to the queue so we know when
// all the events before it have been processed
try {
SunToolkit.flushPendingEvents();
EventQueue.invokeAndWait( new Runnable() {
public void run() {
// dummy implementation
}
} );
} catch(InterruptedException ite) {
System.err.println("Robot.waitForIdle, non-fatal exception caught:");
ite.printStackTrace();
} catch(InvocationTargetException ine) {
System.err.println("Robot.waitForIdle, non-fatal exception caught:");
ine.printStackTrace();
}
|