better docs? maybe?
This commit is contained in:
parent
5f24267ebb
commit
fdefd2df08
@ -6,22 +6,33 @@ import java.util.concurrent.TimeUnit
|
|||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class providing methods for programmatic control of mouse and keyboard.
|
* Utility class for programmatically controlling mouse and keyboard actions.
|
||||||
*
|
*
|
||||||
* This uses a Robot instance to facilitate actions like mouse movements,
|
* This class allows performing mouse movements, clicks, and keyboard presses
|
||||||
* clicks, scrolls, and key presses.
|
* through a [Robot] instance. It includes utility methods to add less-robotic
|
||||||
|
* variance and pacing to the actions.
|
||||||
*
|
*
|
||||||
* It contains utility methods to perform actions in a human-like way,
|
* For example, methods like [getAlmostPoint] and the random sleeps in
|
||||||
* including random pacing and wiggle to avoid robotic movement.
|
* [click] and [keypress] help make the automated interactions less robotic.
|
||||||
*
|
*
|
||||||
* Typical usage:
|
* Basic usage:
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* val doer = Doer()
|
* val doer = Doer()
|
||||||
* val nearbyPoint = doer.getAlmostPoint(Point(100, 200), WiggleParams(50, 50))
|
*
|
||||||
* doer.mouseMove(nearbyPoint)
|
* // Move mouse
|
||||||
* doer.click(InputEvent.BUTTON1_DOWN_MASK)
|
* val target = Point(100, 200)
|
||||||
|
* doer.mouseMove(target)
|
||||||
|
*
|
||||||
|
* // Mouse click
|
||||||
|
* doer.click(Doer.LEFT_CLICK)
|
||||||
|
*
|
||||||
|
* // Type keys
|
||||||
|
* doer.keypress(KeyEvent.VK_A)
|
||||||
|
* doer.keypress(KeyEvent.VK_B)
|
||||||
* ```
|
* ```
|
||||||
|
*
|
||||||
|
* @constructor Creates a Doer instance with a Robot.
|
||||||
*/
|
*/
|
||||||
class Doer {
|
class Doer {
|
||||||
|
|
||||||
@ -65,15 +76,16 @@ class Doer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data class to hold parameters for random wiggle amounts when moving the mouse.
|
* Data class to hold parameters for random wiggle amounts when moving the mouse. This is useful for avoiding
|
||||||
|
* "robotic" location patterns on the screen. You'll still converge into an absolutely perfect box, but meh.
|
||||||
*
|
*
|
||||||
* This holds the maximum x and y wiggle offset values to use when randomly
|
* This holds the maximum x and y wiggle offset values to use when randomly
|
||||||
* offsetting mouse movements to make them less robotic.
|
* offsetting mouse movements to make them less robotic.
|
||||||
*
|
*
|
||||||
* For example, this could be passed to [getAlmostPoint] to control the randomization.
|
* For example, this could be passed to [getAlmostPoint] to control the randomization.
|
||||||
*
|
*
|
||||||
* @param xWiggle The max x offset, default 25.
|
* @param xWiggle The max x offset for both parities. So a xWiggle value of 5 will result in a value of x +/- 5, default 25.
|
||||||
* @param yWiggle The max y offset, default 25.
|
* @param yWiggle The max y offset for both parities. So a yWiggle value of 5 will result in a value of y +/- 5, default 25.
|
||||||
*/
|
*/
|
||||||
data class WiggleParams(val xWiggle: Int = 25, val yWiggle: Int = 25)
|
data class WiggleParams(val xWiggle: Int = 25, val yWiggle: Int = 25)
|
||||||
|
|
||||||
@ -102,7 +114,7 @@ class Doer {
|
|||||||
*/
|
*/
|
||||||
fun click(button: Int) {
|
fun click(button: Int) {
|
||||||
robot.mousePress(button)
|
robot.mousePress(button)
|
||||||
sleep(8, 8)
|
sleep(8, 8) //trying to mimic the physiology of pressing and releasing with a clumsy ape finger
|
||||||
robot.mouseRelease(button)
|
robot.mouseRelease(button)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +131,7 @@ class Doer {
|
|||||||
*/
|
*/
|
||||||
fun keypress(key: Int) {
|
fun keypress(key: Int) {
|
||||||
robot.keyPress(key)
|
robot.keyPress(key)
|
||||||
sleep(8, 8)
|
sleep(8, 8) //trying to mimic the physiology of pressing and releasing with a clumsy ape finger
|
||||||
robot.keyRelease(key)
|
robot.keyRelease(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user