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
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected int afterWait  
    protected int beforeWait  
    protected int buttons  
    protected boolean clickDouble  
    protected int innerWait  
    static int LEFT  
    static int MIDDLE  
    protected Location mousePos  
    static int RIGHT  
    static int WHEEL_DOWN  
    static int WHEEL_STEP_DELAY  
    static int WHEEL_UP  
  • Method Summary

    Modifier and Type Method Description
    static Location at()  
    protected static int click​(Location loc, int buttons, Integer modifiers, boolean dblClick, Region region)  
    static Location click​(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 seconds
    static void down​(int buttons)
    press and hold the given buttons Button
    protected static void down​(int buttons, Region region)  
    static int getMouseMovedResponse()
    current setting what to do if mouse is moved outside Sikuli's mouse protection
    static int getRandom()  
    static boolean hasMoved()
    check if mouse was moved since last mouse action
    static boolean hasRandom()  
    static void init()  
    protected static boolean keep​(Object owner)  
    protected static boolean let()  
    protected static boolean let​(Object owner)  
    static int move​(int xoff, int yoff)
    move the mouse from the current position to the offset position given by the parameters
    static int move​(Location loc)
    move the mouse to the given location (local and remote)
    protected static int move​(Location loc, Region region)  
    static void randomize()  
    static void randomize​(long seed)  
    static void reset()  
    static void resetRandom()  
    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)
    static void setMouseMovedCallback​(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 called
    static void setMouseMovedHighlight​(boolean state)  
    static void setRandom()  
    static void setRandom​(int randomOffset)  
    static void up()
    release all buttons
    static void up​(int buttons)
    release the given buttons Button
    protected static void up​(int buttons, Region region)  
    protected static boolean use()  
    protected static boolean use​(Object owner)  
    static void wheel​(int direction, int steps)
    move mouse using mouse wheel in the given direction the given steps
    the result is system dependent
    protected static void wheel​(int direction, int steps, Region region)  
    protected static void wheel​(int direction, int steps, Region region, int stepDelay)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • init

      public static void init()
    • use

      protected static boolean use()
    • use

      protected static boolean use​(Object owner)
    • keep

      protected static boolean keep​(Object owner)
    • let

      protected static boolean let()
    • let

      protected static boolean let​(Object owner)
    • at

      public static Location 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

      public static void setMouseMovedCallback​(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 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

      public static Location click​(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 seconds
      Parameters:
      loc - where to click (not null)
      action - L,R,M left, right, middle - D means double click
      args - timing parameters
      Returns:
      the location
    • click

      protected static int click​(Location loc, int buttons, Integer modifiers, boolean dblClick, Region region)
    • 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

      public static int move​(Location loc)
      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

      protected static int move​(Location loc, Region region)
    • down

      public static void down​(int buttons)
      press and hold the given buttons Button
      Parameters:
      buttons - value
    • down

      protected static void down​(int buttons, Region region)
    • up

      public static void up()
      release all buttons
    • up

      public static void up​(int buttons)
      release the given buttons Button
      Parameters:
      buttons - (0 releases all buttons)
    • up

      protected static void up​(int buttons, Region region)
    • 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 - Button
      steps - value
    • wheel

      protected static void wheel​(int direction, int steps, Region region)
    • wheel

      protected static void wheel​(int direction, int steps, Region region, int stepDelay)