input

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package input is the RemoHop input service: single pointer and keyboard actions on the remote desktop (click, move, type, key, scroll), so that people and AI agents can drive a GUI from the command line in an observe (screenshot), act, verify loop.

Coordinates are pixels of a display exactly as the screenshot service captures it at full size, origin top-left; the host translates them to its virtual screen with the monitor geometry the screenshot service reports. Target.ScaleFrom scales coordinates taken from a downscaled screenshot.

Wire protocol: one "input" stream per action. The request travels in the stream header ({"op": "click"|"move"|"type"|"key"|"scroll", ...}); the host validates it (sizes and key names are bounded and checked on both ends), performs it and answers one JSON message, {"error": "..."} or {"result": {...}}. The client writes nothing else; resetting the stream aborts a long action. Requests are serialised on the host, and every key and button is released when a request ends, however it ends.

The host refuses input when REMOHOP_DESKTOP_VIEW_ONLY is set (as the desktop viewer does). Backends live in internal/inject: XTEST on Linux/X11, SendInput on Windows, Quartz events (CGEventPost, loaded with purego, no cgo) on macOS, where the host needs the Accessibility permission and coordinates are converted from screenshot pixels to display points.

Index

Constants

View Source
const (
	// MaxTextRunes and MaxTextBytes bound one Type call.
	MaxTextRunes = 10000
	MaxTextBytes = 64 << 10
	// MaxCombos bounds the combos (times Repeat) of one Key call.
	MaxCombos = 100
	// MaxScroll bounds the wheel notches of one Scroll call per axis.
	MaxScroll = 100
	// MaxDelay bounds the pause between characters or combos.
	MaxDelay = time.Second

	// DefaultTypeDelay paces typing so applications keep up (xdotool's
	// default too); DefaultKeyDelay separates consecutive combos.
	DefaultTypeDelay = 12 * time.Millisecond
	DefaultKeyDelay  = 30 * time.Millisecond
)

Limits, enforced on both ends.

View Source
const ServiceName = "input"

ServiceName is the stream service of single input actions.

Variables

This section is empty.

Functions

func KeyNames

func KeyNames() string

KeyNames is the list of valid key names, for usage errors and help.

func ValidateCombo

func ValidateCombo(s string) (string, error)

ValidateCombo checks a key combo without sending it and returns its canonical spelling (for example "Control+T" gives "ctrl+t").

Types

type ClickOptions

type ClickOptions struct {
	Target
	Button string // "left" (default), "right" or "middle"
	Double bool   // double-click
}

ClickOptions configures Click.

type KeyOptions

type KeyOptions struct {
	Target               // only used to report the pointer position
	Repeat int           // press the whole sequence this many times (default 1)
	Delay  time.Duration // pause between combos; 0 means DefaultKeyDelay
}

KeyOptions configures Key.

type MoveOptions

type MoveOptions struct {
	Target
}

MoveOptions configures Move.

type Point

type Point struct {
	X int `json:"x"`
	Y int `json:"y"`
}

Point is a pixel position.

type Result

type Result struct {
	Action string `json:"action"` // click, move, type, key or scroll
	// Display is the monitor the coordinates refer to, in virtual-screen
	// pixels.
	Display screenshot.Display `json:"display"`
	// ScaleFrom echoes Target.ScaleFrom when coordinates were scaled.
	ScaleFrom *Size `json:"scale_from,omitempty"`
	// At is where a pointer action happened, in display pixels after
	// scaling; Virtual is the same point on the virtual screen.
	At      *Point `json:"at,omitempty"`
	Virtual *Point `json:"virtual,omitempty"`

	Button string   `json:"button,omitempty"`
	Clicks int      `json:"clicks,omitempty"`
	Keys   []string `json:"keys,omitempty"`  // combos pressed, canonical spelling
	Chars  int      `json:"chars,omitempty"` // characters typed
	DX     int      `json:"dx,omitempty"`
	DY     int      `json:"dy,omitempty"`

	// Pointer is the final pointer position in display pixels (it may lie
	// outside the display, see PointerOnDisplay), PointerScaled the same in
	// ScaleFrom pixels, PointerVirtual on the virtual screen.
	Pointer          Point  `json:"pointer"`
	PointerScaled    *Point `json:"pointer_scaled,omitempty"`
	PointerVirtual   Point  `json:"pointer_virtual"`
	PointerOnDisplay bool   `json:"pointer_on_display"`

	Warning string `json:"warning,omitempty"`
}

Result describes what the host did.

func Click

func Click(ctx context.Context, conn *peer.Conn, x, y int, opts ClickOptions) (*Result, error)

Click moves the pointer to x, y and clicks.

func Key

func Key(ctx context.Context, conn *peer.Conn, combos []string, opts KeyOptions) (*Result, error)

Key presses key combos in sequence, for example "ctrl+c", "Return" or "alt+F4". Modifiers are pressed in the order given and always released.

func Move

func Move(ctx context.Context, conn *peer.Conn, x, y int, opts MoveOptions) (*Result, error)

Move moves the pointer to x, y.

func Scroll

func Scroll(ctx context.Context, conn *peer.Conn, dx, dy int, opts ScrollOptions) (*Result, error)

Scroll turns the mouse wheel: dy notches down (negative: up) and dx notches right (negative: left).

func Type

func Type(ctx context.Context, conn *peer.Conn, text string, opts TypeOptions) (*Result, error)

Type types text into whatever has the keyboard focus. Any Unicode text works, whatever the host's keyboard layout; newlines press Return and tabs press Tab.

type ScrollOptions

type ScrollOptions struct {
	Target
	// At, if set, moves the pointer there first (scrolling goes to the
	// window under the pointer).
	At *Point
}

ScrollOptions configures Scroll.

type Size

type Size struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

Size is an image size, for Target.ScaleFrom.

func ParseSize

func ParseSize(s string) (Size, error)

ParseSize parses "WxH", for example "1280x720".

func (Size) String

func (s Size) String() string

type Target

type Target struct {
	// Display selects the monitor: "" for the primary, an index or a name
	// as `remohop <ID> screenshot --list` prints them, or "all" for the whole
	// virtual screen (the image `screenshot --display all` gives).
	Display string
	// ScaleFrom, when set, says the coordinates are pixels of an image of
	// this size showing the whole display (typically a downscaled
	// screenshot); they are scaled to the display's real pixels. Zero means
	// coordinates are real display pixels.
	ScaleFrom Size
}

Target says which display coordinates refer to and in what scale.

type TypeOptions

type TypeOptions struct {
	Target               // only used to report the pointer position
	Delay  time.Duration // pause after each character; 0 means DefaultTypeDelay
}

TypeOptions configures Type.

Jump to

Keyboard shortcuts

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