DocsUse

Macros

What macros are, how to use the block editor, run once vs. loop, BOOT controls, macro JSON, macros on the microSD card, and the default key set.

What a macro is#

A pelican riding a bicycle drawn in Paint, with a line of text typed below it
Result of the sample macro 画图测试 (Paint test): 271 steps of mouse drawing plus keyboard typing

A macro is a JSON file stored on the device that describes a series of keyboard and mouse steps: key presses, typing, media keys, moves, clicks, scrolling, waits and repeats. Click BOOT and the device runs them in order; nothing needs to run on the computer.

Macros are run by an app on the device, the macro player. The player must be running for a BOOT click to work:

  • When the device web app's home page or macro list says the macro player is not running, click Start.
  • Turn on Start on boot in Settings so the device is ready as soon as it powers on.

BOOT controls#

Macro player idle: shows the current macro's name and step count
Idle: current macro and step count (real device screenshot)
Macro running: progress and current step
Running (real device screenshot)
Stop panel: stopped at step 12
Stopped partway (real device screenshot)
Action Effect
Click Run the current macro
Click while running Stop and reset; the next run starts from step 1
Double-click Switch to the next macro; the screen shows the macro name and i of n (「第 i/n 个」)

While a macro runs, the screen shows the monitor screen: macro name, mode, which round and step, and progress. When it stops, a red stop panel shows which step it stopped at.

NoteWhen an agent or the CLI has armed keyboard and mouse output, pressing BOOT always triggers an emergency stop, and the macro player does not receive the click. Let the other side finish first, or run stick hid-disarm.

Once and loop#

Mode mode in JSON Behavior
Once once A click runs it once
Loop loop A click starts it, it runs round after round, and another click stops and resets it

Choose the mode on the Start block in the block editor.

Block editor#

Block editor: the toolbox on the left, the blocks under Start in the middle, the JSON on the right
Block editor: the sample macro 填单 (Fill form)

On the Macros page of the device web app, click New, or click Edit on an existing macro.

  • Toolbox: on the left, color-coded by category: keyboard, mouse, timing, flow.
  • Drag and drop: drag blocks into the stack under Start; on release a block snaps to the nearest position. Dragging a block takes the blocks below it along; dropping it back on the toolbox deletes it. On a phone, tap a block in the toolbox to add it after the selected block.
  • Repeat: a C-shaped block that wraps the blocks to repeat; nests at most 4 levels deep.
  • Fields: edit them on the block. A key name opens an 87-key keyboard, or use Record key to capture a key by pressing it; modifiers toggle one by one; Move to can pick a point on a mini screen.
  • Field names: shows the JSON field names on the blocks, matching the JSON on the right; macro extension fields are outlined with a dashed line.
  • Label: any block can have a label, which is shown on the device screen when that step runs.
  • Undo / redo: Ctrl+Z / Ctrl+Shift+Z. Delete removes only the selected block (a repeat together with its contents), and the blocks below move up.
  • Validation: invalid blocks are marked in red, and a macro with errors cannot be saved.
  • Test run: save first; the page counts down 3 seconds, then runs the macro once without changing the current macro.
  • Export / import: a macro is exported as a JSON file and imported on the macro list page.
  • Save conflicts: if someone else changed the macro after you opened it, the page lets you load their version, save yours as a copy, or overwrite.
Category Block Fields Effect
Start mode One per macro; choose once or loop
Keyboard Tap tap mods Tap a key, optionally with modifiers, such as Ctrl+S
Keyboard Key down / Key up down / up Hold down or release a key; Key up can release all keys
Keyboard Type text Type a string of English text and symbols
Keyboard Media media Volume, playback, brightness and other media keys
Mouse Move to moveto Move to a position on the primary display, as a percentage
Mouse Move move Move by a number of pixels, relative to where the mouse is
Mouse Click click n Left, right, middle, back or forward button; can click several times
Mouse Mouse down / Mouse up press / release Following moves carry the button with them, for dragging and drawing lines
Mouse Scroll / H-scroll wheel / hwheel Direction and number of notches
Timing Wait / Random wait wait Wait a number of milliseconds; Random wait picks a value in a range
Flow Repeat repeat steps Repeat the wrapped blocks a number of times

Macro list#

Macro list: four macros on the device, one on the microSD card
Macro list
Action Description
Set as current Choose which macro a BOOT click runs
Test run Count down 3 seconds, then run it once without changing the current macro
Duplicate Copy it under a new name
Move to microSD / Move to device Move between device storage and the microSD card
Export JSON Download to your computer
Delete Cannot be undone

In the web app, the current macro must be stored on the device, so that BOOT keeps working with the microSD card removed. That is why the current macro cannot be moved to the card or deleted directly: set another macro as current first.

Macro JSON#

Macro steps use the same names and meanings as the HID API actions; see API reference: POST /v1/hid. A step without extension fields and with values in the API ranges is, as written, a valid API action.

JSON
{"name": "示例", "mode": "once", "steps": [
  {"tap": "A", "mods": ["ctrl"], "label": "全选"},
  {"text": "hello"},
  {"wait": 500},
  {"repeat": 3, "steps": [{"tap": "TAB"}]},
  {"moveto": [50, 50]},
  {"click": "left"}
]}

In this example, the name 示例 means "Example" and the label 全选 means "Select all".

Steps shared with the API:

Step Meaning
{"tap":"S","mods":["ctrl","shift"]} Tap a key; mods are the modifiers pressed with it
{"down":"LSHIFT"} / {"up":"LSHIFT"} Hold / release a key; down can carry mods, and {"up":"all"} releases every key
{"text":"hello"} Type text; English letters, symbols, newlines and tabs only
{"media":"volume_up"} Media key
{"move":[dx,dy]} Relative mouse movement, ±2000 on each axis
{"click":"left"} Click left right middle back forward
{"press":"left"} / {"release":"left"} Hold / release a mouse button
{"wheel":-3} / {"hwheel":3} Wheel notches, ±127, not 0; up and right are positive
{"wait":500} Wait in milliseconds

Key names use the canonical 87-key spelling, such as A, ENTER and LSHIFT; modifier names are ctrl shift alt gui, with an r prefix for the right-hand ones; media names look like volume_up and play_pause. All are case-insensitive. For every name, see the name tables.

Macro-only extensions:

Form Meaning
{"repeat":3,"steps":[...]} Repeat 1–1000 times, nested at most 4 levels deep
{"wait":[300,800]} Random wait, picked uniformly in the range; min first
{"moveto":[x,y]} Move to a position on the primary display as a percentage, 0–100
{"click":"left","n":2} Click n times, 1–10
"label" Allowed on any step, up to 24 bytes, shown on the screen when that step runs
Long waits and text wait up to 600000 ms (API: 5000), text up to 1000 characters (API: 256)
  • Top-level fields: name, mode, author, rev, note, steps. Any extra field is an error.
  • rev is a revision number that goes up by 1 on every save; it is used to detect conflicts.

Limits#

Item Limit
Steps 500, counted before repeats are expanded
File size 16 KB
Macro name 48 bytes; must not start with ., _ or a space, or end with a space; must not contain / \ : * ? " < > |; must not be kv

For the full definition, see section 7 of docs/web.md and macro.schema.json on GitHub.

Key set and typing#

  • Macros accept only the standard 87-key set: letters, digits, F1–F12, the editing keys, arrow keys, modifiers and the Menu key, matching a common tenkeyless keyboard, plus 9 media keys. F13–F24 and NumLock are not available.
  • Key presses and typing are mapped using the US keyboard layout.
  • A keyboard device cannot type Chinese. Chinese text has to go through an input method on the computer.
  • When the computer's input method is in Chinese mode, it intercepts English text as well. Switch to English before running.
  • moveto maps only to the computer's primary display.

Timing#

The macro player runs one step at a time, with an extra 10–20 ms between steps. When stopped, it finishes at most the current step; typing is sent in batches of 16 characters, so at most 16 more characters are typed.

For long sequences that need millisecond-accurate timing, use a timeline; see the next section and HTTP API.

microSD card#

The microSD card can hold two kinds of files:

Macros on the card. Same format as macros on the device. They live in /stick/data/macro/ on the card and are listed in the microSD card group of the macro list. The card is a good place for backups and long recordings.

Timeline files. The timeline is the device's low-level execution format: each record is 6 bytes and carries a precise time interval. Large timelines go on the card, and the device plays them while reading, without going through the network; a single file can be up to 16 MB. Timelines are generated by programs, not edited in the block editor.

PowerShell
stick sd put x.tl /stick/macros/x.tl
stick hid-arm 60
stick sd play /stick/macros/x.tl --wait

Arm output before playing a timeline file; --wait shows progress and renews the lease automatically.

CLI and agents#

Command Effect
stick macro ls List macros on the device and the microSD card, the current macro and the player state
stick macro get <name> Get a macro's JSON; -o saves it to a file
stick macro put <file> Validate and upload; --sd puts it on the microSD card
stick macro select <name> Set as the current macro
stick macro run [name] Run the current macro; with a name, do one test run of that macro
stick macro stop Stop the running macro
stick macro rm <name> Delete
  • put validates first; if the macro is invalid, it lists every error, where it is and how to fix it.
  • If the device already has a macro with the same name and a different rev, put refuses to upload; add --force when you are sure you want to overwrite it.
  • run really presses keys, so check the foreground window first.

Agents work with macros through MCP tools of the same names; see Connect an AI agent.

View the source of this page on GitHub