Package org.sikuli.script
Class Mouse
java.lang.Object
org.sikuli.script.Mouse
public class Mouse extends Object
Main pupose is to coordinate the mouse usage among threads
At any one time, the mouse has one owner (usually a Region object)
who exclusively uses the mouse, all others wait for the mouse to be free again
if more than one possible owner is waiting, the next owner is uncertain
It is detected, when the mouse is moved external from the workflow, which can be used for appropriate actions (e.g. pause a script)
the mouse can be blocked for a longer time, so only this owner can use the mouse (like some transactional processing)
Currently deadlocks and infinite waits are not detected, but should not happen ;-)
Contained are methods to use the mouse (click, move, button down/up) as is
At any one time, the mouse has one owner (usually a Region object)
who exclusively uses the mouse, all others wait for the mouse to be free again
if more than one possible owner is waiting, the next owner is uncertain
It is detected, when the mouse is moved external from the workflow, which can be used for appropriate actions (e.g. pause a script)
the mouse can be blocked for a longer time, so only this owner can use the mouse (like some transactional processing)
Currently deadlocks and infinite waits are not detected, but should not happen ;-)
Contained are methods to use the mouse (click, move, button down/up) as is
-
Field Summary
Fields Modifier and Type Field Description protected intafterWaitprotected intbeforeWaitprotected intbuttonsprotected booleanclickDoubleprotected intinnerWaitstatic intLEFTstatic intMIDDLEprotected LocationmousePosstatic intRIGHTstatic intWHEEL_DOWNstatic intWHEEL_STEP_DELAYstatic intWHEEL_UP -
Method Summary
Modifier and Type Method Description static Locationat()protected static intclick(Location loc, int buttons, Integer modifiers, boolean dblClick, Region region)static Locationclick(Location loc, String action, Integer... args)to click (left, right, middle - single or double) at the given location using the given button only useable for local screens timing parameters:
- one value
< 0 wait before mouse down
> 0 wait after mouse up
- 2 or 3 values 1st wait before mouse down
2nd wait after mouse up
3rd inner wait (milli secs, cut to 1000): pause between mouse down and up (Settings.ClickDelay) wait before and after: > 9 taken as milli secs - 1 ... 9 are secondsstatic voiddown(int buttons)press and hold the given buttonsButtonprotected static voiddown(int buttons, Region region)static intgetMouseMovedResponse()current setting what to do if mouse is moved outside Sikuli's mouse protectionstatic intgetRandom()static booleanhasMoved()check if mouse was moved since last mouse actionstatic booleanhasRandom()static voidinit()protected static booleankeep(Object owner)protected static booleanlet()protected static booleanlet(Object owner)static intmove(int xoff, int yoff)move the mouse from the current position to the offset position given by the parametersstatic intmove(Location loc)move the mouse to the given location (local and remote)protected static intmove(Location loc, Region region)static voidrandomize()static voidrandomize(long seed)static voidreset()static voidresetRandom()static voidsetMouseMovedAction(int movedAction)what to do if mouse is moved outside Sikuli's mouse protection
- Mouse.MouseMovedIgnore (0) ignore it (default)
- Mouse.MouseMovedShow (1) show and ignore it
- Mouse.MouseMovedPause (2) show it and pause until user says continue
(2 not implemented yet - 1 is used)static voidsetMouseMovedCallback(Object callBack)what to do if mouse is moved outside Sikuli's mouse protection
only 3 is honored:
in case of event the user provided callBack.happened is calledstatic voidsetMouseMovedHighlight(boolean state)static voidsetRandom()static voidsetRandom(int randomOffset)static voidup()release all buttonsstatic voidup(int buttons)release the given buttonsButtonprotected static voidup(int buttons, Region region)protected static booleanuse()protected static booleanuse(Object owner)static voidwheel(int direction, int steps)move mouse using mouse wheel in the given direction the given steps
the result is system dependentprotected static voidwheel(int direction, int steps, Region region)protected static voidwheel(int direction, int steps, Region region, int stepDelay)
-
Field Details
-
mousePos
-
clickDouble
protected boolean clickDouble -
buttons
protected int buttons -
beforeWait
protected int beforeWait -
innerWait
protected int innerWait -
afterWait
protected int afterWait -
LEFT
public static final int LEFT- See Also:
- Constant Field Values
-
MIDDLE
public static final int MIDDLE- See Also:
- Constant Field Values
-
RIGHT
public static final int RIGHT- See Also:
- Constant Field Values
-
WHEEL_UP
public static final int WHEEL_UP- See Also:
- Constant Field Values
-
WHEEL_DOWN
public static int WHEEL_DOWN -
WHEEL_STEP_DELAY
public static final int WHEEL_STEP_DELAY- See Also:
- Constant Field Values
-
-
Method Details
-
init
public static void init() -
use
protected static boolean use() -
use
-
keep
-
let
protected static boolean let() -
let
-
at
-
reset
public static void reset() -
getMouseMovedResponse
public static int getMouseMovedResponse()current setting what to do if mouse is moved outside Sikuli's mouse protection- Returns:
- current setting see
setMouseMovedAction(int)
-
setMouseMovedAction
public static void setMouseMovedAction(int movedAction)what to do if mouse is moved outside Sikuli's mouse protection
- Mouse.MouseMovedIgnore (0) ignore it (default)
- Mouse.MouseMovedShow (1) show and ignore it
- Mouse.MouseMovedPause (2) show it and pause until user says continue
(2 not implemented yet - 1 is used)- Parameters:
movedAction- value
-
setMouseMovedCallback
what to do if mouse is moved outside Sikuli's mouse protection
only 3 is honored:
in case of event the user provided callBack.happened is called- Parameters:
callBack- ObserverCallBack
-
setMouseMovedHighlight
public static void setMouseMovedHighlight(boolean state) -
hasMoved
public static boolean hasMoved()check if mouse was moved since last mouse action- Returns:
- true/false
-
click
to click (left, right, middle - single or double) at the given location using the given button only useable for local screens timing parameters:
- one value
< 0 wait before mouse down
> 0 wait after mouse up
- 2 or 3 values 1st wait before mouse down
2nd wait after mouse up
3rd inner wait (milli secs, cut to 1000): pause between mouse down and up (Settings.ClickDelay) wait before and after: > 9 taken as milli secs - 1 ... 9 are seconds- Parameters:
loc- where to click (not null)action- L,R,M left, right, middle - D means double clickargs- timing parameters- Returns:
- the location
-
click
-
randomize
public static void randomize() -
randomize
public static void randomize(long seed) -
getRandom
public static int getRandom() -
setRandom
public static void setRandom() -
setRandom
public static void setRandom(int randomOffset) -
resetRandom
public static void resetRandom() -
hasRandom
public static boolean hasRandom() -
move
move the mouse to the given location (local and remote)- Parameters:
loc- Location- Returns:
- 1 for success, 0 otherwise
-
move
public static int move(int xoff, int yoff)move the mouse from the current position to the offset position given by the parameters- Parameters:
xoff- horizontal offset (< 0 left, > 0 right)yoff- vertical offset (< 0 up, > 0 down)- Returns:
- 1 for success, 0 otherwise
-
move
-
down
public static void down(int buttons)press and hold the given buttonsButton- Parameters:
buttons- value
-
down
-
up
public static void up()release all buttons -
up
public static void up(int buttons)release the given buttonsButton- Parameters:
buttons- (0 releases all buttons)
-
up
-
wheel
public static void wheel(int direction, int steps)move mouse using mouse wheel in the given direction the given steps
the result is system dependent- Parameters:
direction-Buttonsteps- value
-
wheel
-
wheel
-