Package org.dreambot.api.input
Class Mouse
- java.lang.Object
-
- org.dreambot.api.input.Mouse
-
public class Mouse extends java.lang.Object
Please note: In general you do not have to concern yourself with these methods.
The methods here will be called from interact methods by the API (such as the interact method inRectangleDestination
)
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
addModifierFromClick(MouseButton mode)
Adds to the current modifier based on theMouseButton.getMask()
called before aMouseEvent.MOUSE_PRESSED
eventstatic boolean
click()
Triggers a left clickstatic boolean
click(boolean right)
Triggers a left clickstatic boolean
click(java.awt.Point destination)
Moves mouse to point, and preforms left click.static boolean
click(java.awt.Point destination, boolean right)
Moves mouse to point, and preforms desired type of click, as determines by arguments.static boolean
click(java.awt.Rectangle destination)
Moves mouse to rectangle, and preforms left click.static boolean
click(java.awt.Rectangle destination, boolean right)
Moves mouse to rectangle, and preforms desired type of click, as determines by arguments.static boolean
click(ClickMode mode)
Deprecated.static boolean
click(MouseButton mode)
Triggers a click as determined by theMouseButton
static boolean
click(AbstractMouseDestination destination)
Moves mouse to destination, and preforms left click.static boolean
click(AbstractMouseDestination<?> destination, MouseButton type)
Triggers a click based fromMouseButton
at desiredAbstractMouseDestination
.static boolean
click(AbstractMouseDestination destination, boolean right)
Moves mouse to destination, and preforms desired type of click, as determines by arguments.static boolean
click(AbstractMouseDestination destination, ClickMode type)
Deprecated.static boolean
click(Entity destination)
Moves mouse to entity, and preforms left click.static boolean
click(Entity destination, boolean right)
Moves mouse to entity, and preforms desired type of click, as determines by arguments.static boolean
drag(java.awt.Point point)
Drags the mouse from current point to the given pointstatic boolean
drag(java.awt.Rectangle rectangle)
Drags the mouse from current position to the given Rectanglestatic boolean
drag(AbstractMouseDestination<?> destination)
Drags the mouse to the given AbstractMouseDestination Automatically temporarily disables mouse hop if enabledstatic boolean
drag(Tile tile)
Drags the mouse from the current point to the given Tilestatic boolean
drag(Entity entity)
Drags the mouse from the current position to the given Entitystatic int
getCrosshairColorID()
Gets the current crosshair color of the mouse.static CrosshairState
getCrosshairState()
Gets the current crosshair color of the mouse.static int
getCurrentModifiers()
Gets the current event modifiers from holding mouse buttonsstatic MouseAlgorithm
getDefaultMouseAlgorithm()
Returns DreamBot's defaultStandardMouseAlgorithm
mouse algorithm implementation Primarily used for backwards compatibility forMouseMovementAlgorithm
default click implementationsstatic java.util.List<Entity>
getEntitiesOnCursor()
Gets a list of the entities that the cursor is hovering overstatic int
getIdleTime()
Gets the idle time.static java.awt.Point
getLastClicked()
Gets last clicked position by the clientstatic long
getLastClickedTime()
Returns the last click time in milliseconds.static int
getLastClickedX()
Gets last clicked x position by the clientstatic int
getLastClickedY()
Gets last clicked y position by the clientstatic int
getLastCrosshairColorID()
Gets the crosshair color from the last click.static double
getLastMouseDirection()
static double
getLastMouseMagnitude()
static long
getLastMouseMoveTime()
static MouseAlgorithm
getMouseAlgorithm()
Returns the currently setstatic MouseMovementAlgorithm
getMouseMovementAlgorithm()
Deprecated.static long
getMouseMoveResetTimeMillis()
static MouseSettings
getMouseSettings()
Grabs the MouseSettingsstatic long[]
getOnCursorUIDs()
static java.awt.Point
getPointOutsideScreen()
Returns a random point slightly off of the game canvasstatic java.awt.Point
getPosition()
Gets the current mouse positionstatic long[]
getRawOnCursorUIDs()
static int
getRSLastClickedX()
static int
getRSLastClickedY()
static Tile
getTileOnCursor()
Gets the closest tile that it on the mouse's cursorstatic int
getUIDCount()
static int
getX()
Gets the current mouse X coordinate of the mousestatic int
getY()
Gets the current mouse Y coordinate of the mousestatic boolean
hop(int x, int y)
Method to 'hop' the mouse position, instantly.static boolean
hop(java.awt.Point destination)
Method to 'hop' the mouse position, instantly.static boolean
isAlwaysHop()
static boolean
isButtonPressed(MouseButton button)
static boolean
isForceDrag()
static boolean
isMouseDragging()
static boolean
isMouseHeldDown()
static boolean
isMouseInScreen()
Method to determine if the mouse cursor is in the screen.static boolean
loseFocus(int sleepBeforeLoseFocus)
Moves mouse outside of screen, sleeps for the given amount in ms, then calls a focus lost event Does not run if client already doesn't have focus If Mouse is already outside of screen, it will not re-move it outside of screenstatic void
mouseDownUntil(int timeout, Condition c)
Hold mouse down until condition is true, with specified timeout Does not create its own thread!static boolean
move()
Moves the mouse to random gaussian distributed destination near the location of your current position if the mouse is on screen, otherwise will base position from center of canvas.static boolean
move(java.awt.Point point)
Moves the mouse to a specified pointstatic boolean
move(java.awt.Rectangle rectangle)
Moves the mouse to a specified rectanglestatic boolean
move(AbstractMouseDestination<?> destination)
Moves the mouse to a destination Does not click" IfisAlwaysHop()
is true, automatically adjust to callhop(Point)
usingAbstractMouseDestination.getSuitablePoint()
static boolean
move(Tile tile)
static boolean
move(Entity entity)
Moves the mouse to a destinationstatic boolean
moveMouseOutsideScreen()
Deprecated.static boolean
moveOutsideScreen()
Moves the mouse outside the screen and sends a focus lost event to the canvas SeemoveOutsideScreen(boolean)
with param truestatic boolean
moveOutsideScreen(boolean loseFocus)
Moves mouse outside the screen, losing focus based on loseFocus parameter Does not run if mouse is not in screen If loseFocus is true seeloseFocus(int)
with a default time of random(100,3000)static void
removeModifierFromClick(MouseButton mode)
Removes the mask given byMouseButton.getMask()
, called after aMouseEvent.MOUSE_CLICKED
eventstatic void
resetButtons()
static boolean
scroll(boolean up, int timeout, Condition c)
Scrolls mouse until the condition is true, with specified timeoutstatic boolean
scrollDown(int timeout, Condition c)
Scrolls mouse wheel down until Condition is true or timeout is metstatic void
scrollDownUntil(int timeout, Condition c)
Deprecated.static void
scrollUntil(boolean up, int timeout, Condition c)
Scrolls mouse until the condition is true, with specified timeoutstatic boolean
scrollUp(int timeout, Condition c)
Scrolls mouse wheel up until Condition is true or timeout is metstatic void
scrollUpUntil(int timeout, Condition c)
Deprecated.static void
setAlwaysHop(boolean alwaysHop)
static void
setForceDrag(boolean forceDrag)
static void
setLastClickPosition(java.awt.Point lastClickPosition2)
static void
setLastCrosshairColorID(int last)
Set internally during mouse click operationsstatic void
setLastMouseDirection(double lastMouseDirection2)
static void
setLastMouseMagnitude(double lastMouseMagnitude2)
static void
setLastMouseMoveTime(long lastMouseMoveTime2)
static void
setMouseAlgorithm(MouseAlgorithm algorithm)
Sets the mouse algorithm implementation the client uses for mouse movement and clicksstatic void
setMouseDragging(boolean dragging)
static void
setMouseMovementAlgorithm(MouseMovementAlgorithm algorithm)
Deprecated.static void
setPosition(int x, int y)
static void
toggleButtonPressed(MouseButton button, boolean pressed)
-
-
-
Method Detail
-
setMouseMovementAlgorithm
@Deprecated public static void setMouseMovementAlgorithm(MouseMovementAlgorithm algorithm)
Deprecated.Sets the mouse algorithm the client uses.- Parameters:
algorithm
- This is the algorithm that the client will use during mouse move events
-
setMouseAlgorithm
public static void setMouseAlgorithm(MouseAlgorithm algorithm)
Sets the mouse algorithm implementation the client uses for mouse movement and clicks- Parameters:
algorithm
-MouseAlgorithm
implementation
-
getMouseMovementAlgorithm
@Deprecated public static MouseMovementAlgorithm getMouseMovementAlgorithm()
Deprecated.Returns the currently set mouse algorithm.- Returns:
- The currently set mouse algorithm
-
getDefaultMouseAlgorithm
public static MouseAlgorithm getDefaultMouseAlgorithm()
Returns DreamBot's defaultStandardMouseAlgorithm
mouse algorithm implementation Primarily used for backwards compatibility forMouseMovementAlgorithm
default click implementations
-
setPosition
public static void setPosition(int x, int y)
-
getUIDCount
public static int getUIDCount()
-
getRawOnCursorUIDs
public static long[] getRawOnCursorUIDs()
-
getOnCursorUIDs
public static long[] getOnCursorUIDs()
-
getIdleTime
public static int getIdleTime()
Gets the idle time.- Returns:
- the idle time.
-
getLastClicked
public static java.awt.Point getLastClicked()
Gets last clicked position by the client- Returns:
- the position of the last mouse click the client performed
-
getLastClickedTime
public static long getLastClickedTime()
Returns the last click time in milliseconds. If there haven't been any clicks it will return 0. This method only counts clicks sent by the client itself, manual mouse clicks won't be reflected by this.- Returns:
- Last click time in milliseconds, or 0 if there haven't been any clicks since client start
-
getLastClickedX
public static int getLastClickedX()
Gets last clicked x position by the client- Returns:
- the x position of the last mouse click the client performed
-
getLastClickedY
public static int getLastClickedY()
Gets last clicked y position by the client- Returns:
- the y position of the last mouse click the client performed
-
getX
public static int getX()
Gets the current mouse X coordinate of the mouse- Returns:
- X coordinate of the mouse
-
getY
public static int getY()
Gets the current mouse Y coordinate of the mouse- Returns:
- Y coordinate of the mouse
-
getPosition
public static java.awt.Point getPosition()
Gets the current mouse position- Returns:
Point
of the position of the mouse
-
getMouseSettings
public static MouseSettings getMouseSettings()
Grabs the MouseSettings
-
getCrosshairColorID
public static int getCrosshairColorID()
Gets the current crosshair color of the mouse.- Returns:
- 0, 1, 2
-
getCrosshairState
public static CrosshairState getCrosshairState()
Gets the current crosshair color of the mouse.- Returns:
- Crosshair state
-
getLastCrosshairColorID
public static int getLastCrosshairColorID()
Gets the crosshair color from the last click.- Returns:
- 0, 1, 2
-
setLastCrosshairColorID
public static void setLastCrosshairColorID(int last)
Set internally during mouse click operations- Parameters:
last
-
-
getEntitiesOnCursor
public static java.util.List<Entity> getEntitiesOnCursor()
Gets a list of the entities that the cursor is hovering over- Returns:
- list of entities
-
getTileOnCursor
public static Tile getTileOnCursor()
Gets the closest tile that it on the mouse's cursor- Returns:
- the closest tile if one exists, null otherwise
-
click
public static boolean click(java.awt.Rectangle destination)
Moves mouse to rectangle, and preforms left click.- Parameters:
destination
- The rectangle destination you wish click.- Returns:
- true if clicked successfully.
-
click
public static boolean click(java.awt.Rectangle destination, boolean right)
Moves mouse to rectangle, and preforms desired type of click, as determines by arguments.- Parameters:
destination
- The rectangle destination you wish click.right
- The type of click you wish to preform, right click if true, otherwise left click.- Returns:
- true if clicked successfully.
-
click
public static boolean click(java.awt.Point destination)
Moves mouse to point, and preforms left click.- Parameters:
destination
- The point destination you wish click.- Returns:
- true if clicked successfully.
-
click
public static boolean click(java.awt.Point destination, boolean right)
Moves mouse to point, and preforms desired type of click, as determines by arguments.- Parameters:
destination
- The point destination you wish click.right
- The type of click you wish to preform, right click if true, otherwise left click.- Returns:
- true if clicked successfully.
-
click
public static boolean click(Entity destination)
Moves mouse to entity, and preforms left click.- Parameters:
destination
- TheEntity
destination you wish click.- Returns:
- true if clicked successfully.
-
click
public static boolean click(Entity destination, boolean right)
Moves mouse to entity, and preforms desired type of click, as determines by arguments.- Parameters:
destination
- TheEntity
destination you wish click.right
- The type of click you wish to preform, right click if true, otherwise left click.- Returns:
- true if clicked successfully.
-
click
public static boolean click(AbstractMouseDestination destination, boolean right)
Moves mouse to destination, and preforms desired type of click, as determines by arguments.- Parameters:
destination
- The destination you wish click.right
- The type of click you wish to preform, right click if true, otherwise left click.- Returns:
- true if clicked successfully.
-
click
public static boolean click()
Triggers a left click- Returns:
- true if clicked successfully
-
click
public static boolean click(boolean right)
Triggers a left click- Returns:
- true if clicked successfully
-
click
@Deprecated public static boolean click(ClickMode mode)
Deprecated.
-
click
public static boolean click(MouseButton mode)
Triggers a click as determined by theMouseButton
- Returns:
- true if clicked successfully
-
click
public static boolean click(AbstractMouseDestination destination)
Moves mouse to destination, and preforms left click.- Parameters:
destination
- The destination you wish click.- Returns:
- true if clicked successfully.
-
click
@Deprecated public static boolean click(AbstractMouseDestination destination, ClickMode type)
Deprecated.
-
click
public static boolean click(AbstractMouseDestination<?> destination, MouseButton type)
Triggers a click based fromMouseButton
at desiredAbstractMouseDestination
. Performs the full press, release, clicked operation.- Parameters:
destination
- theAbstractMouseDestination
you wish to click.type
- theMouseButton
used to determine type of click to preform.- Returns:
- true if clicked successfully
-
mouseDownUntil
public static void mouseDownUntil(int timeout, Condition c)
Hold mouse down until condition is true, with specified timeout Does not create its own thread!- Parameters:
timeout
- timeout in millisecondsc
- condition to check
-
scrollUntil
public static void scrollUntil(boolean up, int timeout, Condition c)
Scrolls mouse until the condition is true, with specified timeout- Parameters:
up
- true to scroll uptimeout
- timeout in millisecondsc
- condition to check
-
scroll
public static boolean scroll(boolean up, int timeout, Condition c)
Scrolls mouse until the condition is true, with specified timeout- Parameters:
up
- true to scroll uptimeout
- timeout in millisecondsc
- condition to check
-
scrollDownUntil
@Deprecated public static void scrollDownUntil(int timeout, Condition c)
Deprecated.
-
scrollDown
public static boolean scrollDown(int timeout, Condition c)
Scrolls mouse wheel down until Condition is true or timeout is met- Parameters:
timeout
- timeout in millisecondsc
- Condition to check
-
scrollUpUntil
@Deprecated public static void scrollUpUntil(int timeout, Condition c)
Deprecated.
-
scrollUp
public static boolean scrollUp(int timeout, Condition c)
Scrolls mouse wheel up until Condition is true or timeout is met- Parameters:
timeout
- timeout in millisecondsc
- Condition to check
-
move
public static boolean move(java.awt.Rectangle rectangle)
Moves the mouse to a specified rectangle- Parameters:
rectangle
- The rectangle to move the mouse to.- Returns:
- true if mouse moved successfully
-
move
public static boolean move(Entity entity)
Moves the mouse to a destination- Parameters:
entity
- theEntity
which to move the mouse to.- Returns:
- true if mouse moved successfully, otherwise false.
-
move
public static boolean move(java.awt.Point point)
Moves the mouse to a specified point- Parameters:
point
- The point to move the mouse to.- Returns:
- true if mouse moved successfully
-
move
public static boolean move(Tile tile)
-
move
public static boolean move(AbstractMouseDestination<?> destination)
Moves the mouse to a destination Does not click" IfisAlwaysHop()
is true, automatically adjust to callhop(Point)
usingAbstractMouseDestination.getSuitablePoint()
- Parameters:
destination
- Destination to move the mouse to.- Returns:
- true if mouse moved successfully
-
move
public static boolean move()
Moves the mouse to random gaussian distributed destination near the location of your current position if the mouse is on screen, otherwise will base position from center of canvas.- Returns:
- true if mouse moved successfully, otherwise false.
-
drag
public static boolean drag(java.awt.Point point)
Drags the mouse from current point to the given point- Parameters:
point
- Point to drag mouse to- Returns:
- True if successfully dragged, else false
-
drag
public static boolean drag(Tile tile)
Drags the mouse from the current point to the given Tile- Parameters:
tile
- Tile to drag mouse to- Returns:
- True if successfully dragged, else false
-
drag
public static boolean drag(Entity entity)
Drags the mouse from the current position to the given Entity- Parameters:
entity
- Entity to drag mouse to- Returns:
- True if successfully dragged, else false
-
drag
public static boolean drag(java.awt.Rectangle rectangle)
Drags the mouse from current position to the given Rectangle- Parameters:
rectangle
- The rectangle to drag the mouse to.- Returns:
- True if successfully dragged, else false
-
drag
public static boolean drag(AbstractMouseDestination<?> destination)
Drags the mouse to the given AbstractMouseDestination Automatically temporarily disables mouse hop if enabled- Parameters:
destination
- AbstractMouseDestination to drag mouse to- Returns:
- True if successfully dragged, else false
-
moveMouseOutsideScreen
@Deprecated public static boolean moveMouseOutsideScreen()
Deprecated.
-
moveOutsideScreen
public static boolean moveOutsideScreen()
Moves the mouse outside the screen and sends a focus lost event to the canvas SeemoveOutsideScreen(boolean)
with param true
-
moveOutsideScreen
public static boolean moveOutsideScreen(boolean loseFocus)
Moves mouse outside the screen, losing focus based on loseFocus parameter Does not run if mouse is not in screen If loseFocus is true seeloseFocus(int)
with a default time of random(100,3000)- Parameters:
loseFocus
- Boolean whether to lose focus or not- Returns:
- True if mouse already not in screen, or if successfully moves out of screen and if required loses focus
-
loseFocus
public static boolean loseFocus(int sleepBeforeLoseFocus)
Moves mouse outside of screen, sleeps for the given amount in ms, then calls a focus lost event Does not run if client already doesn't have focus If Mouse is already outside of screen, it will not re-move it outside of screen- Parameters:
sleepBeforeLoseFocus
- MS to sleep before calling focus lost- Returns:
- True if client already is not focused or if mouse successfully moves outside of screen and focus is lost
-
isMouseInScreen
public static boolean isMouseInScreen()
Method to determine if the mouse cursor is in the screen.- Returns:
- True if mouse is in the screen
-
hop
public static boolean hop(java.awt.Point destination)
Method to 'hop' the mouse position, instantly.- Parameters:
destination
- Point to jump to- Returns:
- True if succeeded.
-
hop
public static boolean hop(int x, int y)
Method to 'hop' the mouse position, instantly.- Parameters:
x
- X-coordinatey
- Y-coordinate- Returns:
- True if succeeded.
-
getPointOutsideScreen
public static java.awt.Point getPointOutsideScreen()
Returns a random point slightly off of the game canvas- Returns:
- a randomized Point outside the game canvas
-
setLastClickPosition
public static void setLastClickPosition(java.awt.Point lastClickPosition2)
-
getLastMouseMagnitude
public static double getLastMouseMagnitude()
-
setLastMouseMagnitude
public static void setLastMouseMagnitude(double lastMouseMagnitude2)
-
getLastMouseDirection
public static double getLastMouseDirection()
-
setLastMouseDirection
public static void setLastMouseDirection(double lastMouseDirection2)
-
getLastMouseMoveTime
public static long getLastMouseMoveTime()
-
setLastMouseMoveTime
public static void setLastMouseMoveTime(long lastMouseMoveTime2)
-
getMouseMoveResetTimeMillis
public static long getMouseMoveResetTimeMillis()
-
isAlwaysHop
public static boolean isAlwaysHop()
-
setAlwaysHop
public static void setAlwaysHop(boolean alwaysHop)
-
getRSLastClickedX
public static int getRSLastClickedX()
-
getRSLastClickedY
public static int getRSLastClickedY()
-
getCurrentModifiers
public static int getCurrentModifiers()
Gets the current event modifiers from holding mouse buttons
-
addModifierFromClick
public static void addModifierFromClick(MouseButton mode)
Adds to the current modifier based on theMouseButton.getMask()
called before aMouseEvent.MOUSE_PRESSED
event
-
removeModifierFromClick
public static void removeModifierFromClick(MouseButton mode)
Removes the mask given byMouseButton.getMask()
, called after aMouseEvent.MOUSE_CLICKED
event
-
toggleButtonPressed
public static void toggleButtonPressed(MouseButton button, boolean pressed)
-
isButtonPressed
public static boolean isButtonPressed(MouseButton button)
-
resetButtons
public static void resetButtons()
-
setMouseDragging
public static void setMouseDragging(boolean dragging)
-
isForceDrag
public static boolean isForceDrag()
-
setForceDrag
public static void setForceDrag(boolean forceDrag)
-
isMouseHeldDown
public static boolean isMouseHeldDown()
-
isMouseDragging
public static boolean isMouseDragging()
-
getMouseAlgorithm
public static MouseAlgorithm getMouseAlgorithm()
Returns the currently set
-
-