Skip to content

JSON Format

ZMouse stores recorded events in JSON format for easy editing and portability.

File Structure

json
{
  "version": 1,
  "events": [
    {"t": 0, "type": "move", "x": 500, "y": 300},
    {"t": 150, "type": "left_down", "x": 500, "y": 300},
    {"t": 200, "type": "left_up", "x": 500, "y": 300},
    {"t": 500, "type": "key_down", "x": 0, "y": 0, "data": 65},
    {"t": 550, "type": "key_up", "x": 0, "y": 0, "data": 65}
  ]
}

Fields

Top Level

FieldTypeDescription
versionnumberFormat version (currently 1)
eventsarrayArray of event objects

Event Object

FieldTypeDescription
tnumberTimestamp in milliseconds since recording started
typestringEvent type
xnumberMouse X coordinate (0 for keyboard events)
ynumberMouse Y coordinate (0 for keyboard events)
datanumber(Optional) Wheel delta or virtual key code

Event Types

TypeDescription
moveMouse cursor moved
left_downLeft mouse button pressed
left_upLeft mouse button released
right_downRight mouse button pressed
right_upRight mouse button released
wheelMouse scroll wheel
key_downKeyboard key pressed
key_upKeyboard key released

Data Field

The data field is only present for certain event types:

Wheel Events

For wheel events, data contains the scroll delta:

  • Positive values: scroll up
  • Negative values: scroll down
  • Units are multiples of 120 (WHEEL_DELTA)
json
{"t": 300, "type": "wheel", "x": 500, "y": 300, "data": 120}

Keyboard Events

For key_down and key_up events, data contains the virtual key code:

json
{"t": 500, "type": "key_down", "x": 0, "y": 0, "data": 65}

Common virtual key codes:

CodeKey
8Backspace
9Tab
13Enter
16Shift
17Ctrl
18Alt
27Escape
32Space
37Left Arrow
38Up Arrow
39Right Arrow
40Down Arrow
48-570-9
65-90A-Z
112-123F1-F12

Example: Click Sequence

A single left-click at (500, 300):

json
{
  "version": 1,
  "events": [
    {"t": 0, "type": "move", "x": 500, "y": 300},
    {"t": 50, "type": "left_down", "x": 500, "y": 300},
    {"t": 100, "type": "left_up", "x": 500, "y": 300}
  ]
}

Example: Double-Click

A double-click at (200, 200):

json
{
  "version": 1,
  "events": [
    {"t": 0, "type": "move", "x": 200, "y": 200},
    {"t": 50, "type": "left_down", "x": 200, "y": 200},
    {"t": 100, "type": "left_up", "x": 200, "y": 200},
    {"t": 150, "type": "left_down", "x": 200, "y": 200},
    {"t": 200, "type": "left_up", "x": 200, "y": 200}
  ]
}

Library Usage

zig
const zmouse = @import("zmouse");

// Save events
try zmouse.storage.saveEvents(events, "macro.json", allocator);

// Load events
const loaded = try zmouse.storage.loadEvents("macro.json", allocator);
defer allocator.free(loaded);

Manual Editing Tips

  • Keep timestamps in ascending order
  • Match _down events with corresponding _up events
  • Use consistent timing gaps (50-100ms typical)
  • Test after editing to ensure correct playback

Released under the MIT License.