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
- func KeyNames() string
- func ValidateCombo(s string) (string, error)
- type ClickOptions
- type KeyOptions
- type MoveOptions
- type Point
- type Result
- func Click(ctx context.Context, conn *peer.Conn, x, y int, opts ClickOptions) (*Result, error)
- func Key(ctx context.Context, conn *peer.Conn, combos []string, opts KeyOptions) (*Result, error)
- func Move(ctx context.Context, conn *peer.Conn, x, y int, opts MoveOptions) (*Result, error)
- func Scroll(ctx context.Context, conn *peer.Conn, dx, dy int, opts ScrollOptions) (*Result, error)
- func Type(ctx context.Context, conn *peer.Conn, text string, opts TypeOptions) (*Result, error)
- type ScrollOptions
- type Size
- type Target
- type TypeOptions
Constants ¶
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.
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 ¶
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 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 Key ¶
Key presses key combos in sequence, for example "ctrl+c", "Return" or "alt+F4". Modifiers are pressed in the order given and always released.
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 ¶
Size is an image size, for Target.ScaleFrom.
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.