Skip to main content

Module desktop_input

Module desktop_input 

Source
Expand description

What Desktop does to a native app’s window: mapping a point in a screenshot to the screen, reading a key chord, and (on Windows) sending the input (docs/specs/SPEC_DESKTOP_DRIVING_2026_10_20.md §5.1–5.2).

Everything before win is plain logic, tested on every platform. The rules it enforces are the spec’s defence against a stale or invented coordinate landing on the wrong thing: a point is relative to the image the last look returned, and it is refused if the window moved or resized since, or the point is outside the window.

Modules§

win 🔒
Other platforms: the tool answers that driving is Windows-only for now (spec §8, phases 3 and 4).

Structs§

Chord 🔒
A key chord such as ctrl+shift+s: modifiers held, then one key.
Look 🔒
What the last look at a window returned: where the window was, and the size of the image the agent was shown. Clicks are in that image’s pixels.
Rect 🔒
A window’s place on the screen, in physical pixels.
Region 🔒
A region of the last look, in that look’s pixels, to be shown zoomed.

Enums§

DragStep 🔒
What a drag does to the mouse and keyboard, one step at a time, for run_drag to hand to whatever sends it.

Constants§

DRAG_DROP_MS 🔒
Pause on the last point before the release, so a drop target registers.
DRAG_MIN_MOVES_PER_LEG 🔒
Every leg of a drag has at least this many moves.
DRAG_PIXELS_PER_MOVE 🔒
Roughly one move per this many pixels, so an app that samples the pointer sees a path, not a jump.
DRAG_PRESS_MS 🔒
Pause after the press, before the first move: an app that starts a drag on the first motion needs to have seen the press.
DRAG_SETTLE_MS 🔒
Pause after the pointer arrives and the modifiers go down, before the press.
DRAG_STEP_MS 🔒
Pause between moves.
MAX_DRAG_MOVES 🔒
The most mouse moves one drag sends, however far it goes.
MAX_DRAG_WAYPOINTS 🔒
A drag passes through at most this many given points besides its two ends.
MAX_IMAGE_EDGE 🔒
A screenshot is scaled to at most this on its long edge.
MAX_TEXT_CHARS 🔒
type takes at most this many characters.
MAX_WAIT_MS 🔒
wait takes at most this long.
MAX_ZOOM 🔒
The most a region is enlarged.
MIN_REGION 🔒
The smallest region look zooms into: smaller is not worth an image.
VK_CONTROL 🔒
VK_MENU 🔒
VK_SHIFT 🔒

Statics§

LOOKS 🔒

Functions§

check_of_look 🔒
Whether coordinates the agent says come from look of can be used: they can when of is the window’s latest look. Otherwise the answer says which look is the latest, and whether its size differs from the one the coordinates came from, so the agent knows they are stale.
check_region 🔒
A region inside look’s image, or why not.
check_text 🔒
type’s text must be non-empty, short, and free of control characters other than newline and tab.
describe_scale 🔒
What a look says about how its image relates to the window and to the look before it: the scale (window pixels per image pixel), and a warning when the image’s size changed since the last look of the same window.
drag_path 🔒
The screen points a drag moves through, from start to end by way of via, in order. Each leg is cut into short steps (the last step of a leg lands exactly on its end), and the whole drag is at most MAX_DRAG_MOVES moves. The first point is start itself.
key_code 🔒
The virtual-key code of a key name, or None.
last_look 🔒
What the last look at window id showed, if there was one.
parse_hold 🔒
The modifiers drag may hold while it drags: ctrl, alt and shift, written like a chord without a key (ctrl+shift). The Windows key is refused for the same reason key refuses it.
parse_keys 🔒
Read a chord. The Windows key is refused: a chord with it acts on the operating system (Run, the Start menu, lock), not on the app the user allowed.
remember_look 🔒
Remember what look showed of window id, as the look after the one before it. Returns the look as stored (numbered) and the one it replaced.
run_drag 🔒
Hold modifiers, press the button at the first point, move through the rest, pause, and let go at the last. out does each step. Whatever was pressed is let go again on every exit, including when a step fails: the button first, then the modifiers in reverse, so a failed drag never leaves one held. The first error is the one returned.
scaled_size 🔒
The size a w×h window is shown at: its long edge at most MAX_IMAGE_EDGE, never enlarged.
to_absolute 🔒
A screen point as SendInput wants it with MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_VIRTUALDESK: 0..=65535 across the whole virtual screen, which starts at (vx, vy) and is vw×vh pixels.
to_screen 🔒
The screen point for image point (x, y) of look, given where the window is now. Refuses, with a reason the agent can act on, when the window moved or resized since the look or the point is outside the image.
zoom_for 🔒
How much a w×h region is enlarged: up to MAX_ZOOM, and not past MAX_IMAGE_EDGE on its long edge. Never below 1.