DocsIntegrate
Software-layer SDK
What stick-sdk is, how to install it, and how to use it: click, drag, and type by screen coordinates, with foreground window checks, a human style, and post-run verification.
What it covers#
Keyling has two layers. The hardware layer does one thing: it sends key and mouse actions to the computer on time, following a timeline. Decisions such as where on screen to click, whether the target window is still in the foreground, or whether typing should look human all live in the software-layer SDK, stick-sdk.
| Layer | Tools | Input | Responsible for |
|---|---|---|---|
| Hardware layer | stick, stick-mcp |
Key names, relative moves, timelines | On-time execution, arming and leases, emergency stop, updates |
| Software layer | stick-sdk, stick-sdk-mcp |
Screen coordinates, text to type | Coordinate mapping, pointing, foreground window checks, human style, post-run verification |
The SDK imports the hardware layer's Python package; the hardware layer does not depend on the SDK. If you only send a few keys by name or run macros stored on the device, the hardware layer is enough. To operate windows on the computer by coordinates, use the SDK.
The SDK works purely with coordinates and does not recognize UI elements. Working out where the Save button is falls to the agent or to you; turn it into coordinates first, then hand it to the SDK.
What it can do#
- One plan, one batch: Write moves, clicks, drags, typing, key presses, and scrolling into a single plan. The SDK compiles it into a timeline that the device runs continuously, with no round trips between steps.
- Pointing by screen coordinates: On the primary display, the absolute pointer gets there in one move. On a secondary display, the cursor first moves to the edge of the primary display, then closes in by reading the cursor position in a feedback loop.
- Coordinates that follow the window: Coordinates can be written as units within the target window's client area. If the window moves or is resized, the plan still works unchanged.
- Foreground window checks: A plan declares guards, such as "Notepad must be in the foreground". They are checked before the run and periodically during it, and the device stops immediately if one fails.
- Two styles: Fast and precise by default. You can switch to a human style for a whole plan or for a single step, covering key hold times, gaps between characters, and mouse paths.
- Post-run verification: The computer captures raw input from this device only, then compares it with the plan item by item when the run ends.
- Session cleanup: Output is armed automatically and the lease is renewed during the run. Whether the run ends normally, fails, or is interrupted, all keys are released before output is disarmed.
Requirements#
| Requirement | Details |
|---|---|
| OS | Windows. Reading displays, windows, and the cursor is currently implemented only for Windows |
| Location | Runs on the computer the device is plugged into: the SDK reads the local screen and windows, and both secondary-display pointing and post-run verification require the device to be plugged in locally |
| Device | Already set up on Wi-Fi and paired with the host tools. See The stick command line |
| Environment | Git and uv. The SDK currently runs from the repository; the device does not ship its install package |
NoteThe SDK really moves the cursor, clicks, and types. Confirm the foreground window is the right one before running. Pressing the device's BOOT button triggers an emergency stop at any time.
Install#
git clone https://github.com/kk8o/keyling C:\Projects\keyling
cd C:\Projects\keyling\sdk
uv syncIf you haven't paired yet, pair once. When a number appears on the device screen, click BOOT to allow:
uv run --project ..\host stick pair --wifiThe SDK shares its pairing records with the stick command line. If you have paired only one device, none of the commands below need device arguments.
First run#
The repository includes a sample plan, examples/plans/notepad_hello.json. It requires Notepad to be in the foreground, clicks the center of the client area, types a line of text like a person, then presses Ctrl+End. The steps below walk through it.
1. Open Notepad and check the setup. These two commands are read-only and do not touch the device:
notepad
uv run stick-sdk screen # displays, absolute pointer coverage, foreground window, cursor
uv run stick-sdk windows --class Notepad # find windows: class, process, title, client area, which display2. Compile only. The plan's coordinates are bound to the Notepad window, so Notepad must already be open at this step. Without the window, the command reports that it cannot find the window (找不到窗口 Notepad).
uv run stick-sdk preview examples/plans/notepad_hello.jsonThe output shows the planned duration, the number of segments and records, and keystroke statistics.
3. Run it on the simulator. This does not touch the device or move the real cursor. It reports the final cursor position, the typed text, and the key presses and clicks:
Start-Sleep 3; uv run stick-sdk run examples/plans/notepad_hello.json --sim4. Run it for real. Switch your input method to English first:
Start-Sleep 3; uv run stick-sdk run examples/plans/notepad_hello.json --verifyWith --verify, the SDK reports after the run whether the keys, mouse buttons, and pointer the device actually sent match the plan.
TipThe Start-Sleep 3 in steps 3 and 4 gives you time to switch windows: the plan requires Notepad in the foreground, but the terminal is in front when you press Enter. Click Notepad within 3 seconds of pressing Enter, or increase the delay if that's too short. If the guard is not met, the command reports guard_failed and runs nothing.
Plans#
A plan is a JSON document shared by Python scripts and agents. Here is the sample above:
{
"plan": 1,
"guard": {"foreground": {"class": "Notepad"}},
"frame": {"window": {"class": "Notepad"}, "area": "client", "units": [100, 100], "fit": "stretch"},
"verify": true,
"steps": [
{"do": "click", "at": [50, 50]},
{"do": "type", "text": "Hello from esp-stick, typed like a person.\n", "style": {"kind": "human", "wpm": 60}},
{"do": "key", "keys": "ctrl+end"}
]
}| Part | Purpose |
|---|---|
guard |
Guard: the foreground window must be Notepad. If not, nothing runs; if it stops being true mid-run, an emergency stop follows |
frame |
Coordinate system: Notepad's client area is stretched to 100×100 units, so [50, 50] is the exact center |
steps |
Steps: move_to, click, drag, type, key, scroll, wait |
style |
Style: set on the plan, it applies to every step; set on a step, it applies to that step only |
verify |
Post-run verification |
For every field, step, result, and error code, see Plan format.
Key concepts#
Pointing#
| Where the target is | How it gets there | Condition |
|---|---|---|
| Primary display | Absolute pointer, in one move | None |
| Secondary display | Absolute move to the edge of the primary display nearest the target, then relative moves, reading the cursor in a feedback loop to close in | Device plugged in locally |
| Outside every display | Reports unreachable_point |
On a secondary display, each step reads the cursor once, so it is somewhat slower than on the primary display. Relative-move gains are saved per combination of display layout and mouse settings, so pointing gets more accurate with use. Use stick-sdk gain to view or clear them. If the device is not plugged in locally and the target is not on the primary display, the SDK reports no_pointing.
Coordinates are physical screen pixels, with (0, 0) at the top-left of the primary display. When the plan has a frame, they are units within that area.
Guard checks#
guard is checked once before the run and again every checkpoint_ms milliseconds during it (200 by default). If a check fails, the SDK triggers an emergency stop immediately: the device clears its queue, releases all keys, and disarms. The result is guard_failed, along with which segment the run had reached. Guard checks only read local window information and do not interrupt the device.
Style#
Fast and precise, robot (default) |
Human, human |
|
|---|---|---|
| Typing | Each key held 30 ms, evenly spaced | Hold times and gaps between keys drawn from distributions, pauses between words, Shift pressed first and released last |
| Moving | Straight line at constant speed | Duration based on distance, fast then slow, slightly curved; long moves overshoot and then correct |
| Clicking | Held 30 ms | Held 60–130 ms; double-click interval 70–180 ms |
| Between steps | No pause | Pause of 150–600 ms, configurable |
The human style only changes timing and paths, never results: the final coordinates, typed text, and key press/release pairs are identical to the robot style. With the same seed, the compiled timeline is identical too, which makes runs easy to replay and compare.
Verification#
When a plan has "verify": true, the SDK captures raw input from this device only during the run, then compares it afterwards: the key sequence, the mouse button sequence, absolute coordinates, and the sum of relative moves. Timing deviations are reported but do not count toward pass or fail. Verification only works on Windows with the device plugged in locally. Otherwise the result states why it was skipped, and the run itself is not affected.
Keys and text#
typecan only type ASCII characters on the US layout, plus newlines and tabs. Chinese and other characters reportbad_text. To enter Chinese, use an input method or the clipboard on the computer.keyaccepts only the standard 87-key set (TKL) by default. F13–F24 and NumLock require"keyset": "full"in the plan and are meant only for self-tests and drills.
Command line#
The device options -d, --url, and --key mean the same as in stick, and the environment variables STICK_DEVICE, STICK_URL, and STICK_KEY also work. Add --json to print one line of JSON. On failure, the exit code is 1.
| Command | Purpose | Touches the device |
|---|---|---|
stick-sdk screen |
Displays, absolute pointer coverage, foreground window, cursor | No |
stick-sdk windows [--class C] [--process P] [--title T] |
Visible top-level windows, top to bottom; * marks the foreground window |
No |
stick-sdk preview PLAN.json |
Compile only: segments, record count, planned duration, statistics | No |
stick-sdk show PLAN.json [-o FILE] [--open] |
Render the plan as an HTML page: pointer paths on the desktop and a key timeline | No |
stick-sdk run PLAN.json --sim |
Run on the simulator and report the final cursor, typed text, and clicks | No |
stick-sdk run PLAN.json [--dry-run] [--verify] |
Run the plan | Yes |
stick-sdk selftest [--no-pointer] |
Self-test: compile the samples, check that the human style is reproducible, read the screen, and run a plan with verification | Yes, when the device is local |
stick-sdk gain [--reset] |
View or clear the saved gains for relative pointing | No |
When the device is plugged in locally, selftest presses F13–F17 and moves the cursor, then puts it back. It does not click or type.
For agents#
The SDK includes an MCP server, stick-sdk-mcp. It is already registered in .mcp.json at the repository root, so any MCP-capable agent opened in the repository can use it. To configure it manually:
{"mcpServers": {"stick-sdk": {"command": "uv", "args": ["run", "--project", "sdk", "stick-sdk-mcp"]}}}| Tool | Description |
|---|---|
screen |
Read-only: displays, absolute pointer coverage, foreground window, cursor; can find windows by class, process, or title |
windows |
Read-only: visible top-level windows with class, process, title, client area, and display |
run_plan |
Submit a plan and run it in one go. The first choice for multi-step operations |
move_to, click_at, drag_path, type_text, press_keys, scroll |
Single-step plans, suited to simple one- or two-step operations |
stop |
Emergency stop, immediately |
Recommended workflow:
- Use
screenorwindowsto identify the target window. - Build a plan: put the guard in
guard, and bind coordinates to the target window's client area withframe. - Call
run_planonce with"dry_run": trueto compile without running. A bad plan is caught at this step. - Run it for real. Add
"verify": truewhen you need to confirm the device actually sent the input. - Check
cursor,pointing, andverifyin the result. On failure, checkerrorandstep.
For multi-step operations, submitting one plan is much faster than calling single-step tools one by one: the plan compiles into a single timeline that runs continuously, while single-step tools need a round trip for each step.
The agent's own window is usually in the foreground, so the window you want to operate on usually isn't. In that case, first submit a plan that only clicks it once, with a within guard: the click must land inside the target window and the window must not be covered by another. After the click, the window is in the foreground, and you can run the plan with foreground.
To connect the hardware layer's stick-mcp, see Connect an AI agent. Both servers can be used at the same time.
From Python#
from stick_sdk import connect, Human
with connect() as dev: # no arguments needed if only one device is paired
paint = dev.screen.window(cls="MSPaintApp")
canvas = paint.frame(units=(400, 300), fit="contain", margin=40) # 400×300 units within the client area
with dev.plan(guard=paint.foreground(), frame=canvas) as p:
p.drag([(95, 225), (185, 225), (160, 150)])
p.click((200, 120), count=2)
p.type("done", style=Human(wpm=60)) # only this step is human-like; the rest is fast and precise
r = p.result # already executed when the with block exits
print(r["planned_ms"], r["elapsed_ms"], r["cursor"])- The builder's methods map one-to-one to plan steps.
p.to_json()gives the plan JSON andPlan.from_json(d)goes the other way, losslessly in both directions. p.compile()compiles without running.dev.stop()triggers an emergency stop immediately.
All the examples in the repository really operate the computer:
| File | What it does |
|---|---|
examples/type_notepad.py |
Types in Notepad like a person |
examples/pelican.py |
Draws a pelican riding a bicycle in Paint, as a single timeline |
examples/second_screen.py |
Moves the cursor to the center and then the four corners of the secondary display; moves only, no clicks |
The full Python API reference is on GitHub: sdk/docs/api.md.
Debugging without the device#
| Tool | Use |
|---|---|
stick-sdk preview |
Check the planned duration and statistics, and validate the plan format |
stick-sdk run --sim |
Run the whole execution chain on the simulator: a fake device plus a simulated desktop that mirrors the local display and window layout. Reports the final cursor, typed text, key presses, and clicks |
stick-sdk show |
Draw the plan: the path the pointer takes and when each key goes down and up |
For Python tests, use stick_sdk.sim.Sim. It has the same interface as a real session.
Troubleshooting#
| Error | Meaning | What to do |
|---|---|---|
bad_plan |
The plan format is invalid | Read message; check with preview first |
bad_text |
type contains characters that can't be typed |
Use ASCII only |
guard_failed |
A guard was not met | Bring the target window to the foreground and run again |
unreachable_point |
A coordinate is outside every display | Check the coordinates and frame |
no_pointing |
Pointing by coordinates is not possible | When the device is not local, only the primary display can be targeted |
not_reached |
Feedback-loop pointing on the secondary display didn't arrive within the step limit | Retry; if it still fails, run stick-sdk gain --reset and try again |
hid_stopped |
Output was stopped: someone pressed BOOT, or the host sent a stop | Check the situation, then run again |
unreachable |
Cannot reach the device | See FAQ |
Other hardware-layer error codes are passed through as-is. See HTTP API.
Limits#
- Reading the screen and windows is supported only on Windows.
- The absolute pointer covers only the primary display; secondary displays rely on the feedback loop and require the device to be plugged in locally.
- The SDK does not recognize UI elements, read screen content, or compare screenshots.
- Hardware-layer rate limits and leases still apply. See Safety and limits.