Class VirtualMouse

  • All Implemented Interfaces:
    net.runelite.client.input.MouseListener

    public class VirtualMouse
    extends java.lang.Object
    implements net.runelite.client.input.MouseListener
    • Constructor Summary

      Constructors 
      Constructor Description
      VirtualMouse​(net.runelite.client.input.MouseManager mouseManager, net.runelite.api.Client client)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      VirtualMouse click()
      Clicks the mouse at the current position.
      static java.util.List<java.lang.String> findLibraries()
      Scans a specified directory for JSON files and returns a list of library names derived from the filenames.
      static void loadLibrary​(java.lang.String libraryName)
      Loads a replay library for the REPLAY mouse movement strategy.
      java.awt.event.MouseEvent mouseClicked​(java.awt.event.MouseEvent e)  
      java.awt.event.MouseEvent mouseDragged​(java.awt.event.MouseEvent e)  
      java.awt.event.MouseEvent mouseEntered​(java.awt.event.MouseEvent e)  
      java.awt.event.MouseEvent mouseExited​(java.awt.event.MouseEvent e)  
      java.awt.event.MouseEvent mouseMoved​(java.awt.event.MouseEvent e)  
      java.awt.event.MouseEvent mousePressed​(java.awt.event.MouseEvent e)  
      java.awt.event.MouseEvent mouseReleased​(java.awt.event.MouseEvent e)  
      VirtualMouse move​(ContainerItem item)
      Moves the mouse to the specified ContainerItem.
      VirtualMouse move​(ContainerItem item, MouseMovementStrategy mouseMovementStrategy)
      Moves the mouse to the specified ContainerItem using the provided movement strategy.
      VirtualMouse move​(java.awt.Polygon polygon)
      Moves the mouse to the center of the specified polygon.
      VirtualMouse move​(java.awt.Rectangle rect)
      Moves the mouse to the center of the specified rectangle.
      VirtualMouse move​(net.runelite.api.Actor actor)
      Moves the mouse to the specified Actor.
      VirtualMouse move​(net.runelite.api.Actor actor, MouseMovementStrategy mouseMovementStrategy)
      Moves the mouse to the specified Actor using the provided movement strategy.
      VirtualMouse move​(net.runelite.api.coords.LocalPoint localPoint)
      Moves the mouse to the specified LocalPoint.
      VirtualMouse move​(net.runelite.api.coords.LocalPoint localPoint, int plane)
      Moves the mouse to the specified LocalPoint at a specific plane.
      VirtualMouse move​(net.runelite.api.coords.LocalPoint localPoint, int plane, MouseMovementStrategy mouseMovementStrategy)
      Moves the mouse to the specified LocalPoint at a specific plane using the provided movement strategy.
      VirtualMouse move​(net.runelite.api.coords.LocalPoint localPoint, MouseMovementStrategy mouseMovementStrategy)
      Moves the mouse to the specified LocalPoint using the provided movement strategy.
      VirtualMouse move​(net.runelite.api.coords.WorldPoint worldPoint)
      Moves the mouse to the specified WorldPoint.
      VirtualMouse move​(net.runelite.api.coords.WorldPoint worldPoint, MouseMovementStrategy mouseMovementStrategy)
      Moves the mouse to the specified WorldPoint using the provided movement strategy.
      VirtualMouse move​(net.runelite.api.Point target)
      Moves the mouse to the specified target position using the default mouse movement strategy.
      VirtualMouse move​(net.runelite.api.Point target, MouseMovementStrategy strategy)
      Moves the mouse to the specified target position using the provided movement strategy.
      VirtualMouse move​(net.runelite.api.Tile tile)
      Moves the mouse to the specified Tile.
      VirtualMouse move​(net.runelite.api.TileObject tileObject)
      Moves the mouse to the specified TileObject.
      VirtualMouse move​(net.runelite.api.TileObject tileObject, MouseMovementStrategy mouseMovementStrategy)
      Moves the mouse to the specified TileObject using the provided movement strategy.
      VirtualMouse move​(net.runelite.api.Tile tile, MouseMovementStrategy mouseMovementStrategy)
      Moves the mouse to the specified Tile using the provided movement strategy.
      VirtualMouse move​(net.runelite.api.widgets.Widget widget)
      Moves the mouse to the specified Widget.
      VirtualMouse move​(net.runelite.api.widgets.Widget widget, MouseMovementStrategy mouseMovementStrategy)
      Moves the mouse to the specified Widget using the provided movement strategy.
      static void setMouseMovementStrategy​(MouseMovementStrategy strategy)
      Sets the strategy to be used for mouse movement in the system.
      • Methods inherited from class java.lang.Object

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

      • VirtualMouse

        @Inject
        public VirtualMouse​(net.runelite.client.input.MouseManager mouseManager,
                            net.runelite.api.Client client)
    • Method Detail

      • mouseMoved

        public java.awt.event.MouseEvent mouseMoved​(java.awt.event.MouseEvent e)
        Specified by:
        mouseMoved in interface net.runelite.client.input.MouseListener
      • mouseDragged

        public java.awt.event.MouseEvent mouseDragged​(java.awt.event.MouseEvent e)
        Specified by:
        mouseDragged in interface net.runelite.client.input.MouseListener
      • mouseEntered

        public java.awt.event.MouseEvent mouseEntered​(java.awt.event.MouseEvent e)
        Specified by:
        mouseEntered in interface net.runelite.client.input.MouseListener
      • mouseExited

        public java.awt.event.MouseEvent mouseExited​(java.awt.event.MouseEvent e)
        Specified by:
        mouseExited in interface net.runelite.client.input.MouseListener
      • mousePressed

        public java.awt.event.MouseEvent mousePressed​(java.awt.event.MouseEvent e)
        Specified by:
        mousePressed in interface net.runelite.client.input.MouseListener
      • mouseReleased

        public java.awt.event.MouseEvent mouseReleased​(java.awt.event.MouseEvent e)
        Specified by:
        mouseReleased in interface net.runelite.client.input.MouseListener
      • mouseClicked

        public java.awt.event.MouseEvent mouseClicked​(java.awt.event.MouseEvent e)
        Specified by:
        mouseClicked in interface net.runelite.client.input.MouseListener
      • loadLibrary

        public static void loadLibrary​(java.lang.String libraryName)
        Loads a replay library for the REPLAY mouse movement strategy. Any other strategy will be ignored.
        Parameters:
        libraryName - The name of the library to load.
      • setMouseMovementStrategy

        public static void setMouseMovementStrategy​(MouseMovementStrategy strategy)
        Sets the strategy to be used for mouse movement in the system.

        This method updates the default mouse movement behavior by replacing it with the provided @MouseMovementStrategy implementation. The new strategy will dictate how mouse movements are handled globally.

        Note: It is the caller's responsibility to ensure that the provided strategy implementation is valid and behaves as expected. Passing a null value may lead to unexpected behavior.

        Parameters:
        strategy - The @MouseMovementStrategy to be set as the default mouse movement strategy. Must not be null.
      • findLibraries

        public static java.util.List<java.lang.String> findLibraries()
        Scans a specified directory for JSON files and returns a list of library names derived from the filenames.

        This method attempts to list all files in a predefined directory, extract the filenames, and remove the ".json" extension to identify the libraries.

        In the event of an error during file scanning or processing, it logs the error and returns an empty list.

        Returns:
        A List<String> containing the names of the libraries (filenames without the ".json" extension), or an empty list if an error occurs or no libraries are found.
      • move

        public VirtualMouse move​(net.runelite.api.Point target,
                                 MouseMovementStrategy strategy)
        Moves the mouse to the specified target position using the provided movement strategy.

        This method uses the given MouseMovementStrategy to dictate how the mouse moves to the specified Point target. The movement behavior varies depending on the selected strategy (e.g., linear, bezier, instant, etc.).

        • If the movement strategy is not properly initialized, unexpected behavior may occur.
        • The mouse's final position will be the given Point after the strategy completes.
        Parameters:
        target - The target position represented as a Point to which the mouse will be moved.
        strategy - The MouseMovementStrategy defining how the mouse moves to the target point.
        Returns:
        The VirtualMouse instance for method chaining.
      • move

        public VirtualMouse move​(net.runelite.api.Point target)
        Moves the mouse to the specified target position using the default mouse movement strategy.

        This method leverages the default MouseMovementStrategy to determine how the mouse moves. The behavior of the movement may include various strategies (e.g., linear, curved, instant, etc.) depending on the configuration of the default strategy.

        • If the default mouse movement strategy is not initialized, the behavior may be undefined.
        • The mouse's final position will be the specified target after the strategy completes its execution.
        Parameters:
        target - The target position represented as a Point to which the mouse will move.
        Returns:
        The VirtualMouse instance for method chaining.
      • move

        public VirtualMouse move​(net.runelite.api.Actor actor)
        Moves the mouse to the specified Actor.
        Parameters:
        actor - The actor to move to.
        Returns:
        The VirtualMouse instance for chaining.
      • move

        public VirtualMouse move​(net.runelite.api.Actor actor,
                                 MouseMovementStrategy mouseMovementStrategy)
        Moves the mouse to the specified Actor using the provided movement strategy.
        Parameters:
        actor - The actor to move to.
        mouseMovementStrategy - The movement strategy to use.
        Returns:
        The VirtualMouse instance for chaining.
      • move

        public VirtualMouse move​(ContainerItem item)
        Moves the mouse to the specified ContainerItem.
        Parameters:
        item - The container item to move to.
        Returns:
        The VirtualMouse instance for chaining.
      • move

        public VirtualMouse move​(ContainerItem item,
                                 MouseMovementStrategy mouseMovementStrategy)
        Moves the mouse to the specified ContainerItem using the provided movement strategy.
        Parameters:
        item - The container item to move to.
        mouseMovementStrategy - The movement strategy to use.
        Returns:
        The VirtualMouse instance for chaining.
      • move

        public VirtualMouse move​(net.runelite.api.TileObject tileObject)
        Moves the mouse to the specified TileObject.
        Parameters:
        tileObject - The tile object to move to.
        Returns:
        The VirtualMouse instance for chaining.
      • move

        public VirtualMouse move​(net.runelite.api.TileObject tileObject,
                                 MouseMovementStrategy mouseMovementStrategy)
        Moves the mouse to the specified TileObject using the provided movement strategy.
        Parameters:
        tileObject - The tile object to move to.
        mouseMovementStrategy - The movement strategy to use.
        Returns:
        The VirtualMouse instance for chaining.
      • move

        public VirtualMouse move​(net.runelite.api.Tile tile)
        Moves the mouse to the specified Tile.
        Parameters:
        tile - The tile to move to.
        Returns:
        The VirtualMouse instance for chaining.
      • move

        public VirtualMouse move​(net.runelite.api.Tile tile,
                                 MouseMovementStrategy mouseMovementStrategy)
        Moves the mouse to the specified Tile using the provided movement strategy.
        Parameters:
        tile - The tile to move to.
        mouseMovementStrategy - The movement strategy to use.
        Returns:
        The VirtualMouse instance for chaining.
      • move

        public VirtualMouse move​(net.runelite.api.widgets.Widget widget)
        Moves the mouse to the specified Widget.
        Parameters:
        widget - The widget to move to.
        Returns:
        The VirtualMouse instance for chaining.
      • move

        public VirtualMouse move​(net.runelite.api.widgets.Widget widget,
                                 MouseMovementStrategy mouseMovementStrategy)
        Moves the mouse to the specified Widget using the provided movement strategy.
        Parameters:
        widget - The widget to move to.
        mouseMovementStrategy - The movement strategy to use.
        Returns:
        The VirtualMouse instance for chaining.
      • move

        public VirtualMouse move​(net.runelite.api.coords.WorldPoint worldPoint)
        Moves the mouse to the specified WorldPoint.
        Parameters:
        worldPoint - The world point to move to.
        Returns:
        The VirtualMouse instance for chaining.
      • move

        public VirtualMouse move​(net.runelite.api.coords.WorldPoint worldPoint,
                                 MouseMovementStrategy mouseMovementStrategy)
        Moves the mouse to the specified WorldPoint using the provided movement strategy.
        Parameters:
        worldPoint - The world point to move to.
        mouseMovementStrategy - The movement strategy to use.
        Returns:
        The VirtualMouse instance for chaining.
      • move

        public VirtualMouse move​(net.runelite.api.coords.LocalPoint localPoint)
        Moves the mouse to the specified LocalPoint.
        Parameters:
        localPoint - The local point to move to.
        Returns:
        The VirtualMouse instance for chaining.
      • move

        public VirtualMouse move​(net.runelite.api.coords.LocalPoint localPoint,
                                 MouseMovementStrategy mouseMovementStrategy)
        Moves the mouse to the specified LocalPoint using the provided movement strategy.
        Parameters:
        localPoint - The local point to move to.
        mouseMovementStrategy - The movement strategy to use.
        Returns:
        The VirtualMouse instance for chaining.
      • move

        public VirtualMouse move​(net.runelite.api.coords.LocalPoint localPoint,
                                 int plane)
        Moves the mouse to the specified LocalPoint at a specific plane.
        Parameters:
        localPoint - The local point to move to.
        plane - The plane to move to.
        Returns:
        The VirtualMouse instance for chaining.
      • move

        public VirtualMouse move​(net.runelite.api.coords.LocalPoint localPoint,
                                 int plane,
                                 MouseMovementStrategy mouseMovementStrategy)
        Moves the mouse to the specified LocalPoint at a specific plane using the provided movement strategy.
        Parameters:
        localPoint - The local point to move to.
        plane - The plane to move to.
        mouseMovementStrategy - The movement strategy to use.
        Returns:
        The VirtualMouse instance for chaining.
      • move

        public VirtualMouse move​(java.awt.Rectangle rect)
        Moves the mouse to the center of the specified rectangle.
        Parameters:
        rect - The rectangle to move to.
        Returns:
        The VirtualMouse instance for chaining.
      • move

        public VirtualMouse move​(java.awt.Polygon polygon)
        Moves the mouse to the center of the specified polygon.
        Parameters:
        polygon - The polygon to move to.
        Returns:
        The VirtualMouse instance for chaining.
      • click

        public VirtualMouse click()
        Clicks the mouse at the current position.
        Returns:
        The VirtualMouse instance for chaining.