java.awt
Class Robot
The Robot class is used to simulate user interaction with graphical
programs. It can generate native windowing system input events and
retrieve image data from the current screen. Robot is used to test
the AWT and Swing library implementations; it can also be used to
create self-running demo programs.
Since Robot generates native windowing system events, rather than
simply inserting
AWTEvent
s on the AWT event queue, its use
is not restricted to Java programs. It can be used to
programatically drive any graphical application.
This implementation requires an X server that supports the XTest
extension.
Robot() - Construct a Robot object that operates on the default screen.
|
Robot(GraphicsDevice screen) - Construct a Robot object that operates on the specified screen.
|
BufferedImage | createScreenCapture(Rectangle screenRect) - Create an image containing pixels read from the screen.
|
void | delay(int ms) - Sleep for a specified length of time.
|
int | getAutoDelay() - Retrieve the length of time this Robot sleeps after generating an
event.
|
Color | getPixelColor(int x, int y) - Return the color of the pixel at the given screen coordinates.
|
boolean | isAutoWaitForIdle() - Check if this Robot automatically calls
waitForIdle() after
generating an event.
|
void | keyPress(int keycode) - Press a key.
|
void | keyRelease(int keycode) - Release a key.
|
void | mouseMove(int x, int y) - Move the mouse pointer to absolute coordinates (x, y).
|
void | mousePress(int buttons) - Press one or more mouse buttons.
|
void | mouseRelease(int buttons) - Release one or more mouse buttons.
|
void | mouseWheel(int wheelAmt) - Rotate the mouse scroll wheel.
|
void | setAutoDelay(int ms) - Set the length of time this Robot sleeps after generating an
event.
|
void | setAutoWaitForIdle(boolean isOn) - Set whether or not this Robot automatically calls
waitForIdle() after generating an event.
|
String | toString() - Return a string representation of this Robot.
|
void | waitForIdle() - Wait until all events currently on the event queue have been
dispatched.
|
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
Robot
public Robot()
throws AWTException
Construct a Robot object that operates on the default screen.
AWTException
- if GraphicsEnvironment.isHeadless()
returns true or if the X server does not support the XTest
extensionSecurityException
- if createRobot permission is not
granted
createScreenCapture
public BufferedImage createScreenCapture(Rectangle screenRect)
Create an image containing pixels read from the screen. The
image does not include the mouse pointer.
screenRect
- the rectangle of pixels to capture, in screen
coordinates
- a BufferedImage containing the requested pixels
delay
public void delay(int ms)
Sleep for a specified length of time.
ms
- the length of time in milliseconds
getAutoDelay
public int getAutoDelay()
Retrieve the length of time this Robot sleeps after generating an
event.
- the length of time in milliseconds
getPixelColor
public Color getPixelColor(int x,
int y)
Return the color of the pixel at the given screen coordinates.
x
- the x coordinate of the pixely
- the y coordinate of the pixel
- the Color of the pixel at screen coodinates
(x, y)
isAutoWaitForIdle
public boolean isAutoWaitForIdle()
Check if this Robot automatically calls
waitForIdle()
after
generating an event.
- true if waitForIdle is automatically called
keyPress
public void keyPress(int keycode)
Press a key.
keycode
- key to press, a KeyEvent
VK_ constant
keyRelease
public void keyRelease(int keycode)
Release a key.
keycode
- key to release, a KeyEvent
VK_
constant
mouseMove
public void mouseMove(int x,
int y)
Move the mouse pointer to absolute coordinates (x, y).
x
- the destination x coordinatey
- the destination y coordinate
mousePress
public void mousePress(int buttons)
Press one or more mouse buttons.
buttons
- the buttons to press; a bitmask of one or more of
these InputEvent
fields:
- BUTTON1_MASK
- BUTTON2_MASK
- BUTTON3_MASK
mouseRelease
public void mouseRelease(int buttons)
Release one or more mouse buttons.
buttons
- the buttons to release; a bitmask of one or more
of these InputEvent
fields:
- BUTTON1_MASK
- BUTTON2_MASK
- BUTTON3_MASK
mouseWheel
public void mouseWheel(int wheelAmt)
Rotate the mouse scroll wheel.
wheelAmt
- number of steps to rotate mouse wheel. negative
to rotate wheel up (away from the user), positive to rotate wheel
down (toward the user).
setAutoDelay
public void setAutoDelay(int ms)
Set the length of time this Robot sleeps after generating an
event.
ms
- the length of time in milliseconds
setAutoWaitForIdle
public void setAutoWaitForIdle(boolean isOn)
Set whether or not this Robot automatically calls
waitForIdle()
after generating an event.
isOn
- true if waitForIdle should be called automatically
waitForIdle
public void waitForIdle()
Wait until all events currently on the event queue have been
dispatched.
Robot.java -- a native input event generator
Copyright (C) 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.