Spec-Zone .ru
спецификации, руководства, описания, API
|
|
JavaTM 2 Platform Std. Ed. v1.3.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Robot
This class is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed. The primary purpose of Robot is to facilitate automated testing of Java platform implementations.
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.
Constructor Summary | |
Robot()
Constructs a Robot object in the coordinate system of the primary screen. |
|
Robot(GraphicsDevice screen)
Creates a Robot for the given screen device. |
Method Summary | |
BufferedImage |
createScreenCapture(Rectangle screenRect)
Creates an image containing pixels read from the screen. |
void |
delay(int ms)
Sleeps for the specified time. |
int |
getAutoDelay()
Returns the number of milliseconds this Robot sleeps after generating an event. |
Color |
getPixelColor(int x,
int y)
Returns the color of a pixel at the given screen coordinates. |
boolean |
isAutoWaitForIdle()
Returns whether this Robot automatically invokes waitForIdle
after generating an event. |
void |
keyPress(int keycode)
Presses a given key. |
void |
keyRelease(int keycode)
Releases a given key. |
void |
mouseMove(int x,
int y)
Moves mouse pointer to given screen coordinates. |
void |
mousePress(int buttons)
Presses one or more mouse buttons. |
void |
mouseRelease(int buttons)
Releases one or more mouse buttons. |
void |
setAutoDelay(int ms)
Sets the number of milliseconds this Robot sleeps after generating an event. |
void |
setAutoWaitForIdle(boolean isOn)
Sets whether this Robot automatically invokes waitForIdle
after generating an event. |
String |
toString()
Returns a string representation of this Robot. |
void |
waitForIdle()
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 |
Constructor Detail |
public Robot() throws AWTException
AWTException
- if the platform configuration does not allow low-level input controlSecurityException
- if createRobot
permission is not grantedSecurityManager.checkPermission(java.security.Permission)
,
AWTPermission
public Robot(GraphicsDevice screen) throws AWTException
If screen devices are reconfigured such that the coordinate system is affected, the behavior of existing Robot objects is undefined.
screen
- A screen GraphicsDevice indicating the coordinate
system the Robot will operate in.AWTException
- if the platform configuration does not allow low-level input controlIllegalArgumentException
- if screen
is not a screen
GraphicsDevice.SecurityException
- if createRobot
permission is not grantedGraphicsDevice
,
SecurityManager.checkPermission(java.security.Permission)
,
AWTPermission
Method Detail |
public void mouseMove(int x, int y)
x
- X positiony
- Y positionpublic void mousePress(int buttons)
buttons
- Button mask (combination of InputEvent.BUTTON1/2/3_MASK
)IllegalArgumentException
- if the button mask is not a valid combinationpublic void mouseRelease(int buttons)
buttons
- Button mask (combination of InputEvent.BUTTON1/2/3_MASK
)IllegalArgumentException
- if the button mask is not a valid combinationpublic void keyPress(int keycode)
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.
keyCode
- Key to press (e.g. KeyEvent.VK_A
)IllegalArgumentException
- if keycode
is not a valid keypublic void keyRelease(int keycode)
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.
keyCode
- Key to release (e.g. KeyEvent.VK_A
)IllegalArgumentException
- if keycode
is not a valid keypublic Color getPixelColor(int x, int y)
x
- X position of pixely
- Y position of pixelpublic BufferedImage createScreenCapture(Rectangle screenRect)
screenRect
- Rect to capture in screen coordinatesIllegalArgumentException
- if screenRect
width and height are not greater than zeroSecurityException
- if readDisplayPixels
permission is not grantedSecurityManager.checkPermission(java.security.Permission)
,
AWTPermission
public boolean isAutoWaitForIdle()
waitForIdle
after generating an event.waitForIdle
is automatically calledpublic void setAutoWaitForIdle(boolean isOn)
waitForIdle
after generating an event.isOn
- Whether waitForIdle
is automatically invokedpublic int getAutoDelay()
public void setAutoDelay(int ms)
IllegalArgumentException
- If ms
is not between 0 and 60,000 milliseconds inclusivepublic void delay(int ms)
ms
- Time to sleep in millisecondsIllegalArgumentException
- If ms
is not between 0 and 60,000 milliseconds inclusivepublic void waitForIdle()
IllegalThreadStateException
- if called on the AWT event dispatching threadpublic String toString()
toString
in class Object
|
JavaTM 2 Platform Std. Ed. v1.3.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2001 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.