Class JavaScriptSupport

java.lang.Object
org.sikuli.script.runnerSupport.JavaScriptSupport
All Implemented Interfaces:
IRunnerSupport

public class JavaScriptSupport
extends Object
implements IRunnerSupport
EXPERIMENTAL --- INTERNAL USE ONLY
is not official API --- will not be in version 2
  • Constructor Summary

    Constructors 
    Constructor Description
    JavaScriptSupport()  
  • Method Summary

    Modifier and Type Method Description
    static Object call​(String function, Object... args)
    INTERNAL USE: call interface for JavaScript to be used with predefined functions
    static Object circle​(Object args)  
    static Location click​(Object... args)
    move the mouse with hover() and click using the left button
    static Location doubleClick​(Object... args)
    move the mouse with hover() and double click using the left button
    static Match exists​(Object... args)
    wait for the given visual to appear within the given wait time
    static Object fromJSON​(Object aObj)
    experimental: create the real object from the given JSON
    take care: content length not checked if valid (risk for index out of bounds)
    planned to be used with a socket/RPC based interface to any framework (e.g.
    static Location hover​(Object... args)
    move the mouse to the given location with a given offset
    3 parameter configurations:
    --1: wait for a visual and move mouse to it (args see wait())
    --2: move to the given region/location/match with a given offset
    --3: move to the given offset relative to the last match of the region in use
    static boolean isJSON​(Object aObj)
    check wether the given object is in JSON format as ["ID", ...]
    static boolean isNashorn()  
    static boolean paste​(Object... args)
    just doing a currentRegion.paste(text) (see paste())
    static void restoreUsed()
    INTERNAL USE: restore a saved use() after a use1()
    static Location rightClick​(Object... args)
    move the mouse with hover() and do a right click
    static Object run​(Object... args)  
    boolean runObserveCallback​(Object[] args)
    Run callback for observers.
    static Region use​(Object... args)
    all following undotted function calls will use the given screen or region until this is changed by a later use()
    -- no args: use Screen(0) (this is the default after start)
    -- a number: use Screen(number), Screen(0) if not valid
    -- a region: use the given region
    static Region use1​(Object... args)
    same as use(), but only affects the next processed undotted function after that the use() active before is restored
    static Match wait​(Object... args)
    wait for the given visual to appear within the given wait time
    args [String|Pattern|Double, [Double, [Float]]] (max 3 args)
    arg1: String/Pattern to search or double time to wait (rest ignored)
    arg2: time to wait in seconds
    arg3: minimum similarity to use for search (overwrites Pattern setting)
    static boolean waitVanish​(Object... args)
    wait for the given visual to vanish within the given wait time
    static boolean write​(Object... args)
    just doing a currentRegion.write(text) (see write())

    Methods inherited from class java.lang.Object

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

  • Method Details

    • isNashorn

      public static boolean isNashorn()
      Returns:
      true if we are on Java 8+
    • call

      public static Object call​(String function, Object... args)
      INTERNAL USE: call interface for JavaScript to be used with predefined functions
      Parameters:
      function - the function's name
      args - the parameters
      Returns:
      the object returned by the function or null
    • run

      public static Object run​(Object... args)
    • circle

      public static Object circle​(Object args)
    • use

      public static Region use​(Object... args)
      all following undotted function calls will use the given screen or region until this is changed by a later use()
      -- no args: use Screen(0) (this is the default after start)
      -- a number: use Screen(number), Screen(0) if not valid
      -- a region: use the given region
      Parameters:
      args -
      Returns:
      the used region
    • use1

      public static Region use1​(Object... args)
      same as use(), but only affects the next processed undotted function after that the use() active before is restored
      Parameters:
      args - see use()
      Returns:
      the used region
    • restoreUsed

      public static void restoreUsed()
      INTERNAL USE: restore a saved use() after a use1()
    • wait

      public static Match wait​(Object... args) throws FindFailed
      wait for the given visual to appear within the given wait time
      args [String|Pattern|Double, [Double, [Float]]] (max 3 args)
      arg1: String/Pattern to search or double time to wait (rest ignored)
      arg2: time to wait in seconds
      arg3: minimum similarity to use for search (overwrites Pattern setting)
      Parameters:
      args -
      Returns:
      the match or throws FindFailed
      Throws:
      FindFailed
    • waitVanish

      public static boolean waitVanish​(Object... args)
      wait for the given visual to vanish within the given wait time
      Parameters:
      args - see wait()
      Returns:
      true if not there from beginning or vanished within wait time, false otherwise
    • exists

      public static Match exists​(Object... args)
      wait for the given visual to appear within the given wait time
      Parameters:
      args - see wait()
      Returns:
      the match or null if not found within wait time (no FindFailed exception)
    • hover

      public static Location hover​(Object... args)
      move the mouse to the given location with a given offset
      3 parameter configurations:
      --1: wait for a visual and move mouse to it (args see wait())
      --2: move to the given region/location/match with a given offset
      --3: move to the given offset relative to the last match of the region in use
      Parameters:
      args -
      Returns:
      the evaluated location to where the mouse should have moved
    • click

      public static Location click​(Object... args)
      move the mouse with hover() and click using the left button
      Parameters:
      args - see hover()
      Returns:
      the location, where the click was done
    • doubleClick

      public static Location doubleClick​(Object... args)
      move the mouse with hover() and double click using the left button
      Parameters:
      args - see hover()
      Returns:
      the location, where the double click was done
    • rightClick

      public static Location rightClick​(Object... args)
      move the mouse with hover() and do a right click
      Parameters:
      args - see hover()
      Returns:
      the location, where the right click was done
    • paste

      public static boolean paste​(Object... args)
      just doing a currentRegion.paste(text) (see paste())
      Parameters:
      args - only one parameter being a String
      Returns:
      true if paste() returned 1, false otherwise
    • write

      public static boolean write​(Object... args)
      just doing a currentRegion.write(text) (see write())
      Parameters:
      args - only one parameter being a String
      Returns:
      true if write() returned 1, false otherwise
    • isJSON

      public static boolean isJSON​(Object aObj)
      check wether the given object is in JSON format as ["ID", ...]
      Parameters:
      aObj -
      Returns:
      true if object is in JSON format, false otherwise
    • fromJSON

      public static Object fromJSON​(Object aObj)
      experimental: create the real object from the given JSON
      take care: content length not checked if valid (risk for index out of bounds)
      planned to be used with a socket/RPC based interface to any framework (e.g. C#) Region ["R", x, y, w, h]
      Location ["L", x, y]
      Match ["M", x, y, w, h, score, offx, offy]
      Screen ["S", x, y, w, h, id]
      Pattern ["P", "imagename", score, offx, offy]
      These real objects have a toJSON(), that returns these JSONs
      Parameters:
      aObj -
      Returns:
      the real object or the given object if it is not one of these JSONs
    • runObserveCallback

      public boolean runObserveCallback​(Object[] args)
      Description copied from interface: IRunnerSupport
      Run callback for observers.
      Specified by:
      runObserveCallback in interface IRunnerSupport
      Parameters:
      args - is array for two elements. First is a callback object. Second is an event.
      Returns:
      true if the callback was ran correctly. False in other cases.