org.safs.robot
Class Robot

java.lang.Object
  extended by org.safs.robot.Robot
Direct Known Subclasses:
SAFSRobot

public class Robot
extends java.lang.Object

Utility functions for common user interactions on the system.

See Also:
Robot, CreateUnicodeMap,
JunwuMa SEP 23, 2008 Added doEvents(Robot, Vector) running RobotClipboardPasteEvent with proper delay time for ctrl+v(paste) job done.
CANAGL MAR 25, 2009 Added MouseDrag support
CANAGL APR 03, 2009 Enhance MouseDrag support to work for more apps.
LeiWang JUL 04, 2011 Add methods to maximize, minimize, restore, close window by key-mnemonic.

Constructor Summary
Robot()
           
 
Method Summary
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 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 buttonmask, int nclicks)
          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 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 doubleClick(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 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 InputKeysParser getInputKeysParser()
          Retrieve the active InputKeysParser.
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 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 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 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(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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Robot

public Robot()
Method Detail

getRobot

public static java.awt.Robot getRobot()
                               throws java.awt.AWTException
Retrieve the active java.awt.Robot from the JVM. If one does not yet exist the routine will attempt to instantiate it.

Returns:
java.awt.Robot or a thrown java.awt.AWTException
Throws:
java.awt.AWTException

getInputKeysParser

public static InputKeysParser getInputKeysParser()
Retrieve the active InputKeysParser. If one does not yet exist the routine will attempt to instantiate it.

Returns:
InputKeysParser or null
See Also:
InputKeysParser

getResourceURL

protected static java.net.URL getResourceURL(java.lang.Class clazz,
                                             java.lang.String aresource)

inputKeys

public static java.lang.Object inputKeys(java.lang.String input)
                                  throws java.awt.AWTException
Type keyboard input. The input goes to the current keyboard focus target. The String input can include all special characters and processing as documented in the InputKeysParser class.

Parameters:
input - -- the String of characters to enter.
Returns:
Object Currently we return a Boolean(true) object, but this may be subject to change.
Throws:
java.awt.AWTException - -- if there is a problem instantiating or using the java.awt.Robot
See Also:
InputKeysParser, Robot

inputChars

public static java.lang.Object inputChars(java.lang.String input)
                                   throws java.awt.AWTException
Type keyboard input characters unmodified. No special key processing. The input goes to the current keyboard focus target. The String input will be treated simply as literal text and typed as-is.

Parameters:
input - -- the String of characters to enter.
Returns:
Object Currently we return a Boolean(true) object, but this may be subject to change.
Throws:
java.awt.AWTException - -- if there is a problem instantiating or using the java.awt.Robot
See Also:
InputKeysParser, Robot

click

public static java.lang.Object click(int x,
                                     int y,
                                     int buttonmask,
                                     int nclicks)
                              throws java.awt.AWTException
Workhorse Click routine. Allows us to Click--Press & Release--any combination of InputEvent.BUTTONn_MASK any number of times.

Parameters:
x - screen X coordinate
y - screen Y coordinate
buttonmask - -- specific InputEvent.BUTTONn_MASK(s)
nclicks - -- number of times to click (press and release)
Returns:
Object Currently we return a Boolean(true) object, but this may be subject to change.
Throws:
java.awt.AWTException
See Also:
Robot.mousePress(int), InputEvent.BUTTON1_MASK

clickWithKeyPress

public static java.lang.Object clickWithKeyPress(int x,
                                                 int y,
                                                 int buttonmask,
                                                 int keycode,
                                                 int nclicks)
                                          throws java.awt.AWTException
Workhorse Click with Keypress routine. Allows us to Click--Press & Release--any combination of InputEvent.BUTTONn_MASK any number of times with a single Key Press & Release.

Parameters:
x - screen X coordinate
y - screen Y coordinate
buttonmask - -- specific InputEvent.BUTTONn_MASK(s)
keycode - -- specific keycode to press & release. Ex: KeyEvent.VK_SHIFT
nclicks - -- number of times to click (press and release)
Returns:
Object Currently we return a Boolean(true) object, but this may be subject to change.
Throws:
java.awt.AWTException
See Also:
Robot.mousePress(int), InputEvent.BUTTON1_MASK

click

public static java.lang.Object click(int x,
                                     int y)
                              throws java.awt.AWTException
Move the mouse cursor to the specified x,y coordinates then perform a single mousePress and Release to execute a Click.

Parameters:
x -
y -
Returns:
Object Currently we return a Boolean(true) object, but this may be subject to change.
Throws:
java.awt.AWTException - if instantiating java.awt.Robot throws it.
See Also:
Robot

doubleClick

public static java.lang.Object doubleClick(int x,
                                           int y)
                                    throws java.awt.AWTException
Move the mouse cursor to the specified x,y coordinates then perform a single mousePress and Release to execute a Click.

Parameters:
x -
y -
Returns:
Object Currently we return a Boolean(true) object, but this may be subject to change.
Throws:
java.awt.AWTException - if instantiating java.awt.Robot throws it.
See Also:
Robot

rightClick

public static java.lang.Object rightClick(int x,
                                          int y)
                                   throws java.awt.AWTException
Move the mouse cursor to the specified x,y coordinates then perform a single mousePress and Release to execute a RightClick.

Parameters:
x -
y -
Returns:
Object Currently we return a Boolean(true) object, but this may be subject to change.
Throws:
java.awt.AWTException - if instantiating java.awt.Robot throws it.
See Also:
Robot

click

public static java.lang.Object click(java.awt.Point p)
                              throws java.awt.AWTException
Move the mouse cursor to the specified Point coordinates then perform a single mousePress and Release to execute a Click. This routine simply calls click with the x,y coordinates in the Point.

Parameters:
Point -
Returns:
Object returned from click above.
Throws:
java.awt.AWTException - if instantiating java.awt.Robot throws it.
See Also:
Robot, click(int, int)

rightClick

public static java.lang.Object rightClick(java.awt.Point p)
                                   throws java.awt.AWTException
Move the mouse cursor to the specified Point coordinates then perform a single mousePress and Release to execute a Click. This routine simply calls click with the x,y coordinates in the Point.

Parameters:
Point -
Returns:
Object returned from click above.
Throws:
java.awt.AWTException - if instantiating java.awt.Robot throws it.
See Also:
Robot, click(int, int)

doubleClick

public static java.lang.Object doubleClick(java.awt.Point p)
                                    throws java.awt.AWTException
Move the mouse cursor to the specified Point coordinates then perform a single mousePress and Release to execute a Click. This routine simply calls click with the x,y coordinates in the Point.

Parameters:
Point -
Returns:
Object returned from click above.
Throws:
java.awt.AWTException - if instantiating java.awt.Robot throws it.
See Also:
Robot, click(int, int)

mouseDrag

public static java.lang.Object mouseDrag(java.awt.Point start,
                                         java.awt.Point end,
                                         int buttonMasks)
                                  throws java.awt.AWTException
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.

Parameters:
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 drag
Returns:
Object Currently we return a Boolean(true) object, but this may be subject to change.
Throws:
java.awt.AWTException - if instantiating java.awt.Robot throws it.
See Also:
Robot

leftDrag

public static java.lang.Object leftDrag(java.awt.Point start,
                                        java.awt.Point end)
                                 throws java.awt.AWTException
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.

Parameters:
Point - screen coordinates to start of mouse press and drag.
Point - screen coordinates to end mouse drag and mouse release.
Returns:
Object returned from generic mouseDrag.
Throws:
java.awt.AWTException - if instantiating java.awt.Robot throws it.
See Also:
Robot, mouseDrag(Point,Point,int)

rightDrag

public static java.lang.Object rightDrag(java.awt.Point start,
                                         java.awt.Point end)
                                  throws java.awt.AWTException
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.

Parameters:
Point - screen coordinates to start of mouse press and drag.
Point - screen coordinates to end mouse drag and mouse release.
Returns:
Object returned from generic mouseDrag.
Throws:
java.awt.AWTException - if instantiating java.awt.Robot throws it.
See Also:
Robot

centerDrag

public static java.lang.Object centerDrag(java.awt.Point start,
                                          java.awt.Point end)
                                   throws java.awt.AWTException
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.

Parameters:
Point - screen coordinates to start of mouse press and drag.
Point - screen coordinates to end mouse drag and mouse release.
Returns:
Object returned from generic mouseDrag.
Throws:
java.awt.AWTException - if instantiating java.awt.Robot throws it.
See Also:
Robot

minimizeAllWindows

public static void minimizeAllWindows()
                               throws java.awt.AWTException
Minimize all windows by the short cut 'Windows+M'
This works only for windows system.

Throws:
java.awt.AWTException

getWindowSystemMenu

public static void getWindowSystemMenu()
                                throws java.awt.AWTException
Pre-condition: The window should be focused Get the window system menu by short-cut 'Alt+Space'
This works only for windows system.

Throws:
java.awt.AWTException

minimizeFocusedWindow

public static void minimizeFocusedWindow()
                                  throws java.awt.AWTException
Pre-condition: The window should be focused Minimize window by mnemonic key 'n' of window-system-menu.
This works only for windows system.

Throws:
java.awt.AWTException

maximizeFocusedWindow

public static void maximizeFocusedWindow()
                                  throws java.awt.AWTException
Pre-condition: The window should be focused Minimize window by mnemonic key 'x' of window-system-menu.
This works only for windows system.

Throws:
java.awt.AWTException

restoreFocusedWindow

public static void restoreFocusedWindow()
                                 throws java.awt.AWTException
Pre-condition: The window should be focused Minimize window by mnemonic key 'R' of window-system-menu.
This works only for windows system.

Throws:
java.awt.AWTException

closeFocusedWindow

public static void closeFocusedWindow()
                               throws java.awt.AWTException
Pre-condition: The window should be focused Minimize window by mnemonic key 'C' of window-system-menu.
This works only for windows system.

Throws:
java.awt.AWTException