human

package module
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 9 Imported by: 0

README

Human

Human-like mouse and keyboard for go-rod.

Moves the cursor along randomized Bezier curves and types with natural timing. Works in headless mode (all input goes through CDP). Includes a Direct mode that bypasses all simulation and uses JS-based element methods, guaranteed to work in headless. I needed such functionality in my ThugHunter project, but it proved useful in other automation tasks as well so I made it into a separate package. Inspired by riflosnake/HumanCursor.

Install

go get github.com/smegg99/human

Usage

Look at the examples in the tests for more details on configuration and usage.

cursor := human.New(page)

cursor.Click(element)
cursor.Type("hello world")
Configuration
// Built-in Presets
cursor := human.New(page, human.Fast())      // power user
cursor := human.New(page, human.Swift())     // fast but natural
cursor := human.New(page, human.Casual())    // everyday user
cursor := human.New(page, human.Beginner())  // inexperienced

// Direct mode bypasses all human-like simulation, uses JS element methods.
// Guaranteed to work in headless mode.
cursor := human.New(page, human.Direct())

// Individual options
cursor := human.New(page,
    human.WithTypingSpeed(20, 60),
    human.WithSteadiness(0.5),
    human.WithHesitation(0.3),
)

// Full config
cursor := human.New(page, human.WithConfig(human.Config{
    Hesitation: 0.4,
    MicroPause: 0.2,
    Steadiness: 0.3,
    ClickHold:  [2]int{40, 100},
    ClickDwell: [2]int{100, 300},
    TypeDelay:  [2]int{30, 120},
    ThinkPause: 0.05,
}))
Mouse
cursor.Move(el)
cursor.MoveSteady(el)
cursor.MoveToPoint(500, 300)
cursor.Click(el)
cursor.DoubleClick(el)
cursor.RightClick(el)
cursor.ClickHold(el, 500)
cursor.DragDrop(from, to)
cursor.Scroll(0, 300)
Keyboard
cursor.Type("text")
cursor.TypeWithSpeed("text", 20, 60)
cursor.PressKey(input.Enter)
cursor.KeyCombo([]input.Key{input.ControlLeft}, input.KeyA)
Click and Type
// Clicks the element, clears existing value, types text
cursor.ClickAndType(el, "hello world")

License

MIT

Documentation

Overview

config.go

curve.go

human.go

keyboard.go

mouse.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Direct bypasses all human-like mouse movement, click timing, and
	// keystroke delays. When true, interactions use rod's native element
	// methods directly. It will also use JS-based versions of some methods to avoid issues in headless mode.
	Direct bool

	// Hesitation is the probability of pausing before mouse movement (0-1).
	Hesitation float64

	// MicroPause is the probability of a brief pause mid-movement (0-1).
	MicroPause float64

	// Steadiness controls curve straightness (0 = wobbly, 1 = straight).
	Steadiness float64

	// ClickHold is the [min, max] ms to hold a mouse button during click.
	ClickHold [2]int

	// ClickDwell is the [min, max] ms to pause after a click.
	ClickDwell [2]int

	// TypeDelay is the [min, max] ms between keystrokes.
	TypeDelay [2]int

	// ThinkPause is the probability of a longer pause while typing (0-1).
	ThinkPause float64
}

Config controls cursor timing and behavior.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

type Cursor

type Cursor struct {
	// contains filtered or unexported fields
}

Cursor wraps a rod.Page and tracks the virtual cursor position.

func New

func New(page *rod.Page, opts ...Option) *Cursor

New creates a Cursor for the given page with optional configuration.

func (*Cursor) Click

func (c *Cursor) Click(el *rod.Element) error

Click moves to the element and left-clicks.

func (*Cursor) ClickAndType added in v1.0.2

func (c *Cursor) ClickAndType(el *rod.Element, text string) error

ClickAndType clicks on an element, clears any existing value, then types the given text with human-like keystroke timing.

func (*Cursor) ClickHold

func (c *Cursor) ClickHold(el *rod.Element, holdMs int) error

ClickHold clicks and holds for the given duration in milliseconds.

func (*Cursor) DoubleClick

func (c *Cursor) DoubleClick(el *rod.Element) error

DoubleClick moves to the element and double-clicks.

func (*Cursor) DragDrop

func (c *Cursor) DragDrop(from, to *rod.Element) error

DragDrop drags from one element to another.

func (*Cursor) KeyCombo

func (c *Cursor) KeyCombo(modifiers []input.Key, key input.Key)

KeyCombo presses a key combination (e.g. Ctrl+A).

func (*Cursor) Move

func (c *Cursor) Move(el *rod.Element) error

Move moves the cursor to a random point inside the element.

func (*Cursor) MoveSteady

func (c *Cursor) MoveSteady(el *rod.Element) error

MoveSteady moves to the element with a straight trajectory.

func (*Cursor) MoveToPoint

func (c *Cursor) MoveToPoint(x, y float64)

MoveToPoint moves the cursor to exact coordinates.

func (*Cursor) Pos

func (c *Cursor) Pos() (float64, float64)

Pos returns the current cursor position.

func (*Cursor) PressKey

func (c *Cursor) PressKey(key input.Key)

PressKey presses and releases a single key.

func (*Cursor) RightClick

func (c *Cursor) RightClick(el *rod.Element) error

RightClick moves to the element and right-clicks.

func (*Cursor) Scroll

func (c *Cursor) Scroll(deltaX, deltaY float64)

Scroll dispatches a mouse wheel event. Positive deltaY scrolls down.

func (*Cursor) Type

func (c *Cursor) Type(text string)

Type types text with human-like per-key delays.

func (*Cursor) TypeWithSpeed

func (c *Cursor) TypeWithSpeed(text string, minDelayMs, maxDelayMs int)

TypeWithSpeed types text with custom per-key delay range in milliseconds.

type Option

type Option func(*Config)

Option configures a Cursor.

func Beginner

func Beginner() Option

Beginner returns a configuration with more human-like imperfections.

func Casual

func Casual() Option

Casual returns a configuration that mimics a casual user.

func Direct added in v1.0.4

func Direct() Option

Direct returns a configuration that bypasses all human-like simulation.

func Fast

func Fast() Option

Fast returns a configuration with fatser movements and typing.

func Swift

func Swift() Option

Swift returns a configuration that is faster than average but still human-like.

func WithClickTiming

func WithClickTiming(holdMin, holdMax, dwellMin, dwellMax int) Option

WithClickTiming sets click hold and post-click dwell ranges in ms.

func WithConfig

func WithConfig(cfg Config) Option

WithConfig replaces the entire configuration.

func WithDirect added in v1.0.4

func WithDirect(on bool) Option

WithDirect sets the direct mode flag.

func WithHesitation

func WithHesitation(chance float64) Option

WithHesitation sets the pre-move pause probability (0-1).

func WithMicroPause

func WithMicroPause(chance float64) Option

WithMicroPause sets the mid-move pause probability (0-1).

func WithSteadiness

func WithSteadiness(s float64) Option

WithSteadiness sets curve straightness (0 = wobbly, 1 = straight).

func WithThinkPause

func WithThinkPause(chance float64) Option

WithThinkPause sets the probability of longer pauses while typing (0-1).

func WithTypingSpeed

func WithTypingSpeed(minMs, maxMs int) Option

WithTypingSpeed sets the per-key delay range in ms.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL