public class Robot
extends java.lang.Object
Robot
,
CreateUnicodeMap
,
InputKeysParser
Modifier and Type | Field and Description |
---|---|
static java.awt.datatransfer.Clipboard |
clipboard
The system clip-board, it is a singleton, we keep it in a static field.
|
static int |
DEFAULT_MILLIS_BETWEEN_KEYSTROKES
1
|
static int |
DEFAULT_MILLIS_BETWEEN_MOUSE_RELEASE
800
|
static boolean |
DEFAULT_WAIT_REACTION |
static java.awt.Dimension |
SCREENSZIE |
Constructor and Description |
---|
Robot() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Object |
altLeftDrag(java.awt.Point start,
java.awt.Point end)
Move the mouse cursor to the specified start Point coordinates then perform a
single mousePress (Button1) and drag\move then Release the mouse button at the end point.
|
static java.lang.Object |
centerDrag(java.awt.Point start,
java.awt.Point end)
Move the mouse cursor to the specified start Point coordinates then perform a
single mousePress (Button2) and drag\move then Release the mouse button at the end point.
|
static java.lang.Object |
centerDrag(java.awt.Point start,
java.awt.Point end,
int dndReleaseDelay)
Move the mouse cursor to the specified start Point coordinates then perform a
single mousePress (Button2) and drag\move then Release the mouse button at the end point.
|
static void |
clearClipboard()
Clear the system clip-board.
|
static java.lang.Object |
click(int x,
int y)
Move the mouse cursor to the specified x,y coordinates then perform a
single mousePress and Release to execute a Click.
|
static java.lang.Object |
click(int x,
int y,
int dndReleaseDelay)
Move the mouse cursor to the specified x,y coordinates then perform a
single mousePress and Release to execute a Click.
|
static java.lang.Object |
click(int x,
int y,
int buttonmask,
int nclicks)
Workhorse Click routine.
|
static java.lang.Object |
click(int x,
int y,
int buttonmask,
int nclicks,
int dndReleaseDelay)
Workhorse Click routine.
|
static java.lang.Object |
click(java.awt.Point p)
Move the mouse cursor to the specified Point coordinates then perform a
single mousePress and Release to execute a Click.
|
static java.lang.Object |
clickWithKeyPress(int x,
int y,
int buttonmask,
int keycode,
int nclicks)
Workhorse Click with Keypress routine.
|
static java.lang.Object |
clickWithKeyPress(int x,
int y,
int buttonmask,
int keycode,
int nclicks,
int dndReleaseDelay)
Workhorse Click with Keypress routine.
|
static void |
closeFocusedWindow()
Pre-condition: The window should be focused
Minimize window by mnemonic key 'C' of window-system-menu.
This works only for windows system. |
static java.lang.Object |
ctrlAltLeftDrag(java.awt.Point start,
java.awt.Point end)
Move the mouse cursor to the specified start Point coordinates then perform a
single mousePress (Button1) and drag\move then Release the mouse button at the end point.
|
static java.lang.Object |
ctrlLeftDrag(java.awt.Point start,
java.awt.Point end)
Move the mouse cursor to the specified start Point coordinates then perform a
single mousePress (Button1) and drag\move then Release the mouse button at the end point.
|
static java.lang.Object |
ctrlShiftLeftDrag(java.awt.Point start,
java.awt.Point end)
Move the mouse cursor to the specified start Point coordinates then perform a
single mousePress (Button1) and drag\move then Release the mouse button at the end point.
|
static java.lang.Object |
doubleClick(int x,
int y)
Move the mouse cursor to the specified x,y coordinates then perform a
double mousePress and Release to execute a Click.
|
static java.lang.Object |
doubleClick(java.awt.Point p)
Move the mouse cursor to the specified Point coordinates then perform a
single mousePress and Release to execute a Click.
|
static java.lang.Object |
getClipboard(java.awt.datatransfer.DataFlavor flavor)
Get content from system clip-board.
|
static int |
getDndReleaseDelay() |
static InputKeysParser |
getInputKeysParser()
Retrieve the active InputKeysParser.
|
static int |
getMillisBetweenKeystrokes()
Get the current delay in milliseconds between Robot key events.
|
static java.awt.Point |
getMouseLocation()
get mouse screen location.
|
static boolean |
getNumLock() |
protected static java.net.URL |
getResourceURL(java.lang.Class clazz,
java.lang.String aresource) |
static java.awt.Robot |
getRobot()
Retrieve the active java.awt.Robot from the JVM.
|
static void |
getWindowSystemMenu()
Pre-condition: The window should be focused
Get the window system menu by short-cut 'Alt+Space'
This works only for windows system. |
static java.lang.Object |
inputChars(java.lang.String input)
Type keyboard input characters unmodified.
|
static java.lang.Object |
inputKeys(java.lang.String input)
Type keyboard input.
|
static boolean |
keyPress(int keycode)
Press down a Key.
|
static boolean |
keyRelease(int keycode)
Release a Key.
|
static java.lang.Object |
leftDrag(java.awt.Point start,
java.awt.Point end)
Move the mouse cursor to the specified start Point coordinates then perform a
single mousePress (Button1) and drag\move then Release the mouse button at the end point.
|
static java.lang.Object |
leftDrag(java.awt.Point start,
java.awt.Point end,
int dndReleaseDelay)
Move the mouse cursor to the specified start Point coordinates then perform a
single mousePress (Button1) and drag\move then Release the mouse button at the end point.
|
static void |
main(java.lang.String[] args) |
static void |
maximizeFocusedWindow()
Pre-condition: The window should be focused
Minimize window by mnemonic key 'x' of window-system-menu.
This works only for windows system. |
static void |
minimizeAllWindows()
Minimize all windows by the short cut 'Windows+M'
This works only for windows system. |
static void |
minimizeFocusedWindow()
Pre-condition: The window should be focused
Minimize window by mnemonic key 'n' of window-system-menu.
This works only for windows system. |
static java.lang.Object |
mouseDrag(java.awt.Point start,
java.awt.Point end,
int buttonMasks)
Move the mouse cursor to the specified start Point coordinates then perform a
single mousePress using buttonMasks and drag\move then Release the mouse button at the end point.
|
static java.lang.Object |
mouseDrag(java.awt.Point start,
java.awt.Point end,
int buttonMasks,
int dndReleaseDelay)
Move the mouse cursor to the specified start Point coordinates then perform a
single mousePress using buttonMasks and drag\move then Release the mouse button at the end point.
|
static void |
mouseHover(java.awt.Point point,
int millisStay)
Move the mouse cursor to the specified Point, stay for a period and move out
|
static boolean |
mouseWheel(int wheelAmt)
Scroll the mouse wheel on the object which has focus.
|
static void |
restoreFocusedWindow()
Pre-condition: The window should be focused
Minimize window by mnemonic key 'R' of window-system-menu.
This works only for windows system. |
static java.lang.Object |
rightClick(int x,
int y)
Move the mouse cursor to the specified x,y coordinates then perform a
single mousePress and Release to execute a RightClick.
|
static java.lang.Object |
rightClick(int x,
int y,
int dndReleaseDelay)
Move the mouse cursor to the specified x,y coordinates then perform a
single mousePress and Release to execute a RightClick.
|
static java.lang.Object |
rightClick(java.awt.Point p)
Move the mouse cursor to the specified Point coordinates then perform a
single mousePress and Release to execute a Click.
|
static java.lang.Object |
rightDrag(java.awt.Point start,
java.awt.Point end)
Move the mouse cursor to the specified start Point coordinates then perform a
single mousePress (Button3) and drag\move then Release the mouse button at the end point.
|
static java.lang.Object |
rightDrag(java.awt.Point start,
java.awt.Point end,
int dndReleaseDelay)
Move the mouse cursor to the specified start Point coordinates then perform a
single mousePress (Button3) and drag\move then Release the mouse button at the end point.
|
static void |
setClipboard(java.lang.String content)
Set a string value to the clip-board.
|
static void |
setDndReleaseDelay(int dndReleaseDelay) |
static void |
setDragEndPointOffset(int offsetx,
int offsety)
Set the offset from the end point for dragging.
|
static void |
setDragStartPointOffset(int offsetx,
int offsety)
Set the offset from the start point for dragging.
|
static void |
setMillisBetweenKeystrokes(int msBetween)
Set the delay in milliseconds between Robot key events.
|
static void |
setNumLock(boolean onOff) |
static void |
setWaitReaction(boolean wait)
Set if wait for reaction to "input keys/chars".
|
static void |
setWaitReaction(boolean wait,
int tokenLength,
int dealyForToken,
int dealy)
Set if wait for reaction to "input keys/chars".
|
static java.lang.Object |
shiftLeftDrag(java.awt.Point start,
java.awt.Point end)
Move the mouse cursor to the specified start Point coordinates then perform a
single mousePress (Button1) and drag\move then Release the mouse button at the end point.
|
protected static void |
waitReaction(java.lang.String text)
After Robot input keys/chars into a browser or an application,
the browser/application may need time to react.
|
public static final int DEFAULT_MILLIS_BETWEEN_KEYSTROKES
public static final int DEFAULT_MILLIS_BETWEEN_MOUSE_RELEASE
public static final java.awt.Dimension SCREENSZIE
public static final boolean DEFAULT_WAIT_REACTION
public static final java.awt.datatransfer.Clipboard clipboard
public static void setWaitReaction(boolean wait)
wait
- boolean, if wait or not.public static void setWaitReaction(boolean wait, int tokenLength, int dealyForToken, int dealy)
wait
- boolean, if wait or not.tokenLength
- int, the length of a token. Only if the string is longer than this
then we wait the reaction after input-keys a certain time
indicated by the parameter dealyForToken.dealyForToken
- int, The delay in millisecond to wait the reaction after input-keys
for the string as long as a token.dealy
- int, The constant delay in millisecond to wait the reaction after input-keys.waitReactionDelayInMillisecond
,
waitReactionDelayInMillisecondForToken
,
waitReactionTokenLength
public static void setMillisBetweenKeystrokes(int msBetween)
msBetween
- >= 0inputKeys(String)
,
inputChars(String)
,
doEvents(java.awt.Robot, Vector, int)
public static int getMillisBetweenKeystrokes()
public static int getDndReleaseDelay()
public static void setDndReleaseDelay(int dndReleaseDelay)
dndReleaseDelay
- int, The delay in millisecond before releasing mouse button when 'drag and drop'public static void setDragStartPointOffset(int offsetx, int offsety)
offsetx
- int, offset in x-axisoffsety
- int, offset in y-axismouseDrag(Point, Point, int)
public static void setDragEndPointOffset(int offsetx, int offsety)
offsetx
- int, offset in x-axisoffsety
- int, offset in y-axismouseDrag(Point, Point, int)
public static java.awt.Robot getRobot() throws java.awt.AWTException
java.awt.AWTException
public static InputKeysParser getInputKeysParser()
InputKeysParser
protected static java.net.URL getResourceURL(java.lang.Class clazz, java.lang.String aresource)
public static java.lang.Object inputKeys(java.lang.String input) throws java.awt.AWTException
input
- -- the String of characters to enter.java.awt.AWTException
- -- if there is a problem instantiating or using the
java.awt.RobotInputKeysParser
,
Robot
,
setMillisBetweenKeystrokes(int)
,
doEvents(java.awt.Robot, Vector, int)
public static java.lang.Object inputChars(java.lang.String input) throws java.awt.AWTException
input
- -- the String of characters to enter.java.awt.AWTException
- -- if there is a problem instantiating or using the
java.awt.RobotInputKeysParser
,
Robot
,
setMillisBetweenKeystrokes(int)
,
doEvents(java.awt.Robot, Vector, int)
protected static void waitReaction(java.lang.String text)
public static java.lang.Object click(int x, int y, int buttonmask, int nclicks, int dndReleaseDelay) throws java.awt.AWTException
x
- screen X coordinatey
- screen Y coordinatebuttonmask
- -- specific InputEvent.BUTTONn_MASK(s)nclicks
- -- number of times to click (press and release)dndReleaseDelay
- -- number of millis to wait before final Release.java.awt.AWTException
Robot.mousePress(int)
,
InputEvent.BUTTON1_MASK
public static java.lang.Object click(int x, int y, int buttonmask, int nclicks) throws java.awt.AWTException
x
- screen X coordinatey
- screen Y coordinatebuttonmask
- -- specific InputEvent.BUTTONn_MASK(s)nclicks
- -- number of times to click (press and release)java.awt.AWTException
Robot.mousePress(int)
,
InputEvent.BUTTON1_MASK
public static java.lang.Object clickWithKeyPress(int x, int y, int buttonmask, int keycode, int nclicks, int dndReleaseDelay) throws java.awt.AWTException
x
- screen X coordinatey
- screen Y coordinatebuttonmask
- -- specific InputEvent.BUTTONn_MASK(s)keycode
- -- specific keycode to press & release. Ex: KeyEvent.VK_SHIFTnclicks
- -- number of times to click (press and release)dndReleaseDelay
- -- number of millis to wait before final Release.java.awt.AWTException
Robot.mousePress(int)
,
InputEvent.BUTTON1_MASK
public static java.lang.Object clickWithKeyPress(int x, int y, int buttonmask, int keycode, int nclicks) throws java.awt.AWTException
x
- screen X coordinatey
- screen Y coordinatebuttonmask
- -- specific InputEvent.BUTTONn_MASK(s)keycode
- -- specific keycode to press & release. Ex: KeyEvent.VK_SHIFTnclicks
- -- number of times to click (press and release)java.awt.AWTException
Robot.mousePress(int)
,
InputEvent.BUTTON1_MASK
public static java.lang.Object click(int x, int y, int dndReleaseDelay) throws java.awt.AWTException
x
- y
- dndReleaseDelay
- -- number of millis to wait before final Release.java.awt.AWTException
- if instantiating java.awt.Robot throws it.Robot
public static java.lang.Object click(int x, int y) throws java.awt.AWTException
x
- y
- java.awt.AWTException
- if instantiating java.awt.Robot throws it.Robot
public static java.lang.Object doubleClick(int x, int y) throws java.awt.AWTException
x
- y
- java.awt.AWTException
- if instantiating java.awt.Robot throws it.Robot
public static java.lang.Object rightClick(int x, int y) throws java.awt.AWTException
x
- y
- java.awt.AWTException
- if instantiating java.awt.Robot throws it.Robot
public static java.lang.Object rightClick(int x, int y, int dndReleaseDelay) throws java.awt.AWTException
x
- y
- dndReleaseDelay
- millis between final release.java.awt.AWTException
- if instantiating java.awt.Robot throws it.Robot
public static java.lang.Object click(java.awt.Point p) throws java.awt.AWTException
Point
- java.awt.AWTException
- if instantiating java.awt.Robot throws it.Robot
,
click(int, int)
public static java.lang.Object rightClick(java.awt.Point p) throws java.awt.AWTException
Point
- java.awt.AWTException
- if instantiating java.awt.Robot throws it.Robot
,
click(int, int)
public static java.lang.Object doubleClick(java.awt.Point p) throws java.awt.AWTException
Point
- java.awt.AWTException
- if instantiating java.awt.Robot throws it.Robot
,
click(int, int)
public static java.lang.Object mouseDrag(java.awt.Point start, java.awt.Point end, int buttonMasks, int dndReleaseDelay) throws java.awt.AWTException
Point
- screen coordinates to start of mouse press and drag.Point
- screen coordinates to end mouse drag and mouse release.int
- button masks to use during dragdndReleaseDelay
- millis before final release.java.awt.AWTException
- if instantiating java.awt.Robot throws it.Robot
public static java.lang.Object mouseDrag(java.awt.Point start, java.awt.Point end, int buttonMasks) throws java.awt.AWTException
Point
- screen coordinates to start of mouse press and drag.Point
- screen coordinates to end mouse drag and mouse release.int
- button masks to use during dragjava.awt.AWTException
- if instantiating java.awt.Robot throws it.Robot
public static java.lang.Object altLeftDrag(java.awt.Point start, java.awt.Point end) throws java.awt.AWTException
Point
- screen coordinates to start of mouse press and drag.Point
- screen coordinates to end mouse drag and mouse release.java.awt.AWTException
- if instantiating java.awt.Robot throws it.Robot
,
mouseDrag(Point, Point, int, int[])
public static java.lang.Object ctrlAltLeftDrag(java.awt.Point start, java.awt.Point end) throws java.awt.AWTException
Point
- screen coordinates to start of mouse press and drag.Point
- screen coordinates to end mouse drag and mouse release.java.awt.AWTException
- if instantiating java.awt.Robot throws it.Robot
,
mouseDrag(Point, Point, int, int[])
public static java.lang.Object ctrlLeftDrag(java.awt.Point start, java.awt.Point end) throws java.awt.AWTException
Point
- screen coordinates to start of mouse press and drag.Point
- screen coordinates to end mouse drag and mouse release.java.awt.AWTException
- if instantiating java.awt.Robot throws it.Robot
,
mouseDrag(Point, Point, int, int[])
public static java.lang.Object ctrlShiftLeftDrag(java.awt.Point start, java.awt.Point end) throws java.awt.AWTException
Point
- screen coordinates to start of mouse press and drag.Point
- screen coordinates to end mouse drag and mouse release.java.awt.AWTException
- if instantiating java.awt.Robot throws it.Robot
,
mouseDrag(Point, Point, int, int[])
public static java.lang.Object shiftLeftDrag(java.awt.Point start, java.awt.Point end) throws java.awt.AWTException
Point
- screen coordinates to start of mouse press and drag.Point
- screen coordinates to end mouse drag and mouse release.java.awt.AWTException
- if instantiating java.awt.Robot throws it.Robot
,
mouseDrag(Point, Point, int, int[])
public static boolean mouseWheel(int wheelAmt)
wheelAmt
- int, the wheel amount to scroll.public static boolean keyPress(int keycode)
keycode
- int, keycode Key to press (e.g. KeyEvent.VK_A
)public static boolean keyRelease(int keycode)
keycode
- int, keycode Key to release (e.g. KeyEvent.VK_A
)public static void mouseHover(java.awt.Point point, int millisStay) throws SAFSException
point
- Point, the screen point to hover the mousemillisStay
- int, in milliseconds, the period to hover the mouse; the mouse will
be moved out of screen if it expires.Constants.TIMEOUT_HOVERMOUSE_STAY_FOREVER
, then
the mouse will always stay there forever.SAFSException
- if some error happenspublic static java.lang.Object leftDrag(java.awt.Point start, java.awt.Point end) throws java.awt.AWTException
Point
- screen coordinates to start of mouse press and drag.Point
- screen coordinates to end mouse drag and mouse release.java.awt.AWTException
- if instantiating java.awt.Robot throws it.mouseDrag(Point,Point,int)
public static java.lang.Object rightDrag(java.awt.Point start, java.awt.Point end) throws java.awt.AWTException
Point
- screen coordinates to start of mouse press and drag.Point
- screen coordinates to end mouse drag and mouse release.java.awt.AWTException
- if instantiating java.awt.Robot throws it.mouseDrag(Point,Point,int)
public static java.lang.Object centerDrag(java.awt.Point start, java.awt.Point end) throws java.awt.AWTException
Point
- screen coordinates to start of mouse press and drag.Point
- screen coordinates to end mouse drag and mouse release.java.awt.AWTException
- if instantiating java.awt.Robot throws it.mouseDrag(Point,Point,int)
public static java.lang.Object leftDrag(java.awt.Point start, java.awt.Point end, int dndReleaseDelay) throws java.awt.AWTException
Point
- screen coordinates to start of mouse press and drag.Point
- screen coordinates to end mouse drag and mouse release.dndReleaseDelay
- millisecond before final release.java.awt.AWTException
- if instantiating java.awt.Robot throws it.mouseDrag(Point, Point, int, int)
public static java.lang.Object rightDrag(java.awt.Point start, java.awt.Point end, int dndReleaseDelay) throws java.awt.AWTException
Point
- screen coordinates to start of mouse press and drag.Point
- screen coordinates to end mouse drag and mouse release.dndReleaseDelay
- millisecond before final release.java.awt.AWTException
- if instantiating java.awt.Robot throws it.mouseDrag(Point, Point, int, int)
public static java.lang.Object centerDrag(java.awt.Point start, java.awt.Point end, int dndReleaseDelay) throws java.awt.AWTException
Point
- screen coordinates to start of mouse press and drag.Point
- screen coordinates to end mouse drag and mouse release.dndReleaseDelay
- millisecond before final release.java.awt.AWTException
- if instantiating java.awt.Robot throws it.mouseDrag(Point, Point, int, int)
public static void minimizeAllWindows() throws java.awt.AWTException
java.awt.AWTException
public static java.awt.Point getMouseLocation() throws SAFSException
SAFSException
public static void getWindowSystemMenu() throws java.awt.AWTException
java.awt.AWTException
public static void minimizeFocusedWindow() throws java.awt.AWTException
java.awt.AWTException
public static void maximizeFocusedWindow() throws java.awt.AWTException
java.awt.AWTException
public static void restoreFocusedWindow() throws java.awt.AWTException
java.awt.AWTException
public static void closeFocusedWindow() throws java.awt.AWTException
java.awt.AWTException
public static void clearClipboard()
public static void setClipboard(java.lang.String content)
content
- String, the content to set.public static java.lang.Object getClipboard(java.awt.datatransfer.DataFlavor flavor) throws SAFSException
flavor
- DataFlavor, provides meta information about data.SAFSException
- if there is something wrong.public static void setNumLock(boolean onOff)
onOff
- boolean, Set keyboard's 'NumLock' on or off.public static boolean getNumLock()
public static void main(java.lang.String[] args)
Copyright © SAS Institute. All Rights Reserved.