Medius - BindingsTypes & errors

Types & errors

Every enum, dataclass, and exception the package exposes

Reference for the values the API takes and returns. Field meanings live with each command, so this page links to the Library types and Native API. Raw HID id meanings (keycodes, button slots, Consumer usages) are on Usage IDs.

Every enum subclasses enum.IntEnum, except CatchMask, which is an enum.IntFlag. A member is its wire byte: int(Button.LEFT) == 0, and anywhere an enum is accepted you can pass a bare int instead (handy for a raw HID id with no named member). CatchMask members combine with |.

Injection enums

Button · Action

See the injection model for what each Action means; button slots on Usage IDs.

Button
MemberValue
LEFT0
RIGHT1
MIDDLE2
SIDE13
SIDE24
Action
MemberValueMeaning
SOFT_RELEASE0release unless the user is physically holding it
PRESS1hold down
FORCE_RELEASE2release even against a physical hold

Lock & blanket enums

LockDirection · LockTargetKind · Blanket

See Lock for what a direction and a blanket class mean.

LockDirection
MemberValueBlocks
BOTH0either direction
POSITIVE1+x / +y / wheel-up only
NEGATIVE2-x / -y / wheel-down only
LockTargetKind
MemberValue
X0
Y1
WHEEL2
USAGE3

Built for you by LockTarget.x/y/wheel/usage (and the button/key/media shortcuts); you rarely name it directly.

Blanket
MemberValueClass
AIM0the X and Y cursor axes
WHEEL1the wheel
BUTTONS2every mouse button
KEYS3every keyboard key and modifier
MEDIA4every media usage

These are ABI-local ordinals (matching the crate's Blanket order), not the clip auto-lock scope bits.

Keycode enums

Key · MediaKey

Named subsets of the HID usage tables. The full list of ids and what they do is on Usage IDs (keys) and Usage IDs (media). Any call that takes a Key or MediaKey also accepts a raw int usage.

Key
MembersValues
AZ4 to 29
N1N9, N030 to 39
ENTER ESCAPE BACKSPACE TAB SPACE40 to 44
CAPS_LOCK57
F1F1258 to 69
INSERT HOME PAGE_UP DELETE END PAGE_DOWN73 to 78
RIGHT LEFT DOWN UP (arrows)79 to 82
LEFT_CTRL LEFT_SHIFT LEFT_ALT LEFT_GUI224 to 227
RIGHT_CTRL RIGHT_SHIFT RIGHT_ALT RIGHT_GUI228 to 231
MediaKey
MemberValue
PLAY176
PAUSE177
NEXT_TRACK181
PREV_TRACK182
STOP183
PLAY_PAUSE205
MUTE226
VOLUME_UP233
VOLUME_DOWN234

LED & admin enums

LedTarget · LedMode · RebootTarget

See LED and Admin.

LedTarget
MemberValue
DEVICE0
HOST1
BOTH2
LedMode
MemberValue
AUTO0
OFF1
SOLID2
BLINK3
RebootTarget
MemberValue
DEVICE_DOWNLOAD0
HOST_DOWNLOAD1
DEVICE_RUN2
HOST_RUN3

Emit pace

EmitMode · EmitPace

Passed to dev.set_emit_pace(). See Options.

EmitMode
MemberValue
LEARNED0
INTERVAL1
FIXED2
EmitPace

A frozen dataclass carrying mode and hz. Build it with EmitPace.learned(), EmitPace.interval(), or EmitPace.fixed(hz) (the rate snaps to 1000/n and caps at 1 kHz).

Clip

ClipState · Edge · ClipAction · ClipTrigger · ClipSettings · ClipStatus

The buffered-clip types. Concept on Clip.

ClipState
MemberValueMeaning
IDLE0No clip playing.
PLAYING1Draining the ring, one entry per native frame.
PAUSED2Halted mid-clip; the cursor and any held input are retained.
FAULTED3An append was dropped or the ring overflowed; clear to recover.
Edge
MemberValueFires on
BOTH0either edge of the trigger usage
PRESS1the physical press edge
RELEASE2the physical release edge

Which edge of a ClipTrigger runs its action.

ClipAction
MemberValueRuns
START0rewind and play
STOP1stop and release
PAUSE2halt mid-clip
RESUME3continue from the pause
RESTART4force a rewind and play
TOGGLE5play if idle/paused, stop if playing

The action a bound trigger runs on the box, matching the clip.start/stop/pause/resume/restart/toggle methods.

ClipTrigger

A dataclass binding a physical usage's edge to a clip action, passed to clip.bind(). The box runs the action itself with no host round-trip.

FieldTypeMeaning
onUsagethe trigger usage (button, key, or media)
edgeEdgewhich edge fires the action
actionClipActionwhat the box runs
consumeboolswallow the physical edge so it doesn't pass through (default False)

Construct it directly, e.g. ClipTrigger(Usage.button(Button.SIDE1), Edge.PRESS, ClipAction.TOGGLE, consume=True).

ClipSettings (clip.query_config())
FieldTypeMeaning
autolockList[Blanket]the input groups auto-locked while the clip plays
loopboolplayback loops at the clip end (retained mode only)
retainboolthe loaded clip is retained so it can rewind and replay
finalizedboola retained clip's end is fixed, ready to replay and loop
triggersList[ClipTrigger]the bound trigger set (up to 8)
ClipStatus (clip.query_status())
Field / methodTypeMeaning
stateClipStatethe lifecycle state
free / totalintring bytes free (pace top-ups off this) / retained clip size in bytes (streaming: buffered-but-undrained)
playedintbytes played from the clip start (retained progress; ~0 while streaming)
ticksintcontent frames emitted since the last start (gap runs excluded)
underruns / overruns / seq_gapsintempty-ring / ring-full / dropped-append counts
heldList[Usage]the held-usage snapshot: the buttons, keys, and media the clip is holding down (one shape, like a UsageSnapshot)
is_held(usage)booltest one Usage in held

Stream enums

CatchMask · CatchEventKind · LogLevel

See Catch and Logs & counters; consuming events is on Streams.

CatchMask (IntFlag)
MemberValueSubscribes to
MOTION1cursor motion
WHEEL2wheel
BUTTONS4mouse buttons
KEYS8keyboard keys
MEDIA16media keys
ALL31everything (default)

Combine with |, e.g. CatchMask.BUTTONS | CatchMask.KEYS.

CatchEventKind
MemberValueCatchEvent.payload type
MOTION0MotionEvent
USAGES1UsageSnapshot
LogLevel
MemberValue
ERROR0
WARN1
INFO2
DEBUG3
VERBOSE4

Wire enums

MotionKind · Class · FrameType

Mostly internal. MotionKind and Class tag the structs the Usage and Motion builders produce; FrameType names a wire frame for MockBox.saw() and RecordedFrame.type. Frame semantics are on Frames and Library frames.

MotionKind
MemberValue
CURSOR0
WHEEL1
Class
MemberValue
BUTTON0
KEY1
MEDIA2
FrameType
MemberValueMemberValue
MOVE1LOCK10
INJECT3CATCH11
RESET4MOTION_EVENT12
QUERY5USAGE_EVENT15
RESP6OPTION17
REBOOT_DL7CLIP_APPEND18
LOG8CLIP_CTRL19
LED9CLIP_SET20
CLIP_TRIGGER21

Parameter builders

Usage · Motion · LockTarget

Small classes that wrap a native struct. Build them with their class methods and pass the result to the matching call. Never construct one field by field.

Usage
Usage.button(button) -> Usage
Usage.key(key)       -> Usage
Usage.media(media)   -> Usage

An injection target for dev.inject(input, action). See Inject.

Motion
Motion.cursor(dx, dy) -> Motion
Motion.wheel(delta)   -> Motion

A relative axis drive for dev.move_axis(motion). See Move.

LockTarget
LockTarget.x()            -> LockTarget
LockTarget.y()            -> LockTarget
LockTarget.wheel()        -> LockTarget
LockTarget.usage(usage)   -> LockTarget
LockTarget.button(button) -> LockTarget
LockTarget.key(key)       -> LockTarget
LockTarget.media(media)   -> LockTarget

An axis or usage to lock for dev.lock(target, direction); the button/key/media shortcuts wrap usage(). See Lock.

Device enums

DeviceKind

The cloned device's kind, on DeviceInfo.kind, and what Device.find_mouse_box() / find_keyboard_box() select on. See DeviceKind.

DeviceKind
MemberValue
UNKNOWN0
KEYBOARD1
MOUSE2

Identity & capability types

Version · Health · DeviceInfo · Caps

Dataclasses returned by the queries. Canonical field docs: Library structs.

Version (query_version())
Field / propertyTypeMeaning
proto_verintcontrol-protocol version
fw_majorintfirmware major
fw_minorintfirmware minor
fw_patchintfirmware patch
macbytesthe device chip's base MAC (6 bytes), a stable per-box id
mac_hexstrthe MAC as 12 lowercase hex digits
namestrthe box's human-readable name (a synthesized default when unset), set with set_name
Health (query_health())
FieldType
link_upbool
mouse_attachedbool
clone_configuredbool
injection_activebool
rate_confidentbool
lock_onbool
catch_onbool
kbd_attachedbool
DeviceInfo (device_info())
FieldTypeMeaning
vidintUSB vendor id
pidintUSB product id
bcd_deviceintdevice release (BCD)
bcd_usbintUSB spec (BCD)
has_serialboolexposes a serial string
has_bosboolexposes a BOS descriptor
kindDeviceKindthe device's primary kind (Boot-interface protocol)
productstrthe product string (empty when none)
Caps (caps())
Field / methodTypeMeaning
mouseMouseCapsmouse capabilities
keyboardKbdCapskeyboard capabilities
mouse_change_drivenboolmouse reports only on change
kbd_change_drivenboolkeyboard reports only on change
has_mouse()boola mouse interface is present
has_keyboard()boola keyboard interface is present
is_composite()boolthe clone has more than one HID interface (n_hid > 1)
MouseCaps
FieldTypeMeaning
n_buttonsintbutton count
has_xboolX axis present
has_yboolY axis present
has_wheelboolwheel present
has_report_idboolreports carry a report id
n_hidintHID interface count
KbdCaps
FieldTypeMeaning
n_keysintrollover key count
nkrobooln-key rollover
has_consumerboolConsumer (media) page
has_systemboolSystem-control page
has_report_idboolreports carry a report id

State & telemetry types

Rate · Stats · Locks · CatchState · ImperfectStatus · Counters · PortInfo

More query results, plus PortInfo from find_ports(). Canonical field docs: Library structs.

Rate (query_rate())
Field / methodTypeMeaning
native_period_usintmouse report period, µs
poll_period_usintpoll period, µs
confidentboolestimate is settled
change_drivenboolreports only on change
native_hz()float | Nonerate in Hz, or None if unknown
Stats (query_stats())
FieldTypeMeaning
inject_emitsintinjected reports emitted
tx_dropsintdropped TX frames
tx_mergesintcoalesced TX frames
tx_maxdepthintpeak TX queue depth
tx_wedgesintTX stalls
wakeupsintscheduler wakeups
reset_countintresets seen
config_countintclone configures
Locks (query_locks())
Field / methodTypeMeaning
entriesList[LockEntry]one LockEntry per active lock
is_locked(target, direction)booltest one LockTarget + LockDirection; also true when a whole-class blanket covers it
LockEntry
FieldTypeMeaning
targetLockTargetwhat is locked (an axis or a usage)
is_blanketboola whole-class lock, where target names only the class
positiveboolthe +x / +y / wheel-up / press edge is locked
negativeboolthe -x / -y / wheel-down / release edge is locked
CatchState (query_catch())
FieldTypeMeaning
maskintactive CatchMask bits
droppedintevents dropped by the box
ImperfectStatus (query_imperfect())
FieldTypeMeaning
allowedboolimperfect clones opted in
over_capacityboolmouse exceeds clone capacity
clone_imperfectboolthe live clone is imperfect

See Options.

EmitPaceStatus (query_emit_pace())
FieldTypeMeaning
modeEmitPacethe selected mode
resolved_hzintthe ceiling in effect; 0 = learned/adaptive or no device yet

See Options.

Counters (counters())
FieldTypeMeaning
frames_txinthost-side frames sent
frames_rxinthost-side frames received
crc_dropsintframes dropped on CRC
reconnectsintlink reconnects
PortInfo (find_ports())
FieldTypeMeaning
pathstrserial path, e.g. /dev/ttyACM0 or COM3
vidintUSB vendor id
pidintUSB product id
serialOptional[str]the CH343 adapter's serial, when it serves one

Pass path to Device.open(path). Canonical: PortInfo.

BoxInfo (list_boxes())
Field / propertyTypeMeaning
portPortInfothe box's control port
versionVersionits firmware version, with the box MAC and name
deviceDeviceInfothe device it clones
idstrthe box identity (the MAC hex)
serialOptional[str]the CH343 serial

Pass id or serial to Device.open_by_id(id). Canonical: BoxInfo.

Event & log types

Yielded by the streams

Payloads from streams. dev.catch_events() yields CatchEvent and dev.logs() yields LogLine. What catch reports lives on Catch.

CatchEvent
Field / memberTypeMeaning
kindCatchEventKindwhich payload is set
payloadMotionEvent | UsageSnapshotthe decoded event
motionMotionEvent | Nonepayload when kind == MOTION
usagesUsageSnapshot | Nonepayload when kind == USAGES
MotionEvent
FieldTypeMeaning
dxintX delta
dyintY delta
dzintwheel delta
UsageSnapshot
Field / methodTypeMeaning
usagesList[Usage]every held Usage (button, key, or media; modifiers are key usages 0xE0 to 0xE7)
is_held(usage)booltest a Usage in the snapshot
LogLine
FieldTypeMeaning
levelLogLevelseverity
textstrthe log message
RecordedFrame (MockBox.recorded_frame(idx))
FieldTypeMeaning
typeFrameType | intframe type (raw int if unknown)
seqintframe sequence byte
payloadbytesraw frame payload

Only meaningful with the mock feature.

Errors

MediusError, its subclasses, and the Status codes

Every Blocks call (and any that fails on the wire) raises a MediusError or one of its subclasses. Catch the base class to catch them all. Canonical mapping: Library errors.

MediusError (Exception)
AttributeTypeMeaning
statusStatusthe failure code
messagestrthe box's last error text
proto_verintoffending version byte (bad-proto-version only)
from medius import Device, MediusError, NotFoundError

try:
    dev = Device.find()
except NotFoundError:
    ...                      # no box plugged in
except MediusError as e:     # any other failure
    print(e.status, e.message)
Subclass per Status
ExceptionRaised on
IoErrorERR_IO
NotFoundErrorERR_NOT_FOUND
NoReplyErrorERR_NO_REPLY
BadProtoVerErrorERR_BAD_PROTO_VER
QueryTimeoutErrorERR_QUERY_TIMEOUT
DisconnectedErrorERR_DISCONNECTED
FrameTooLongErrorERR_FRAME_TOO_LONG
FlashToolErrorERR_FLASH_TOOL
InvalidArgErrorERR_INVALID_ARG
PanicErrorERR_PANIC

DisconnectedError ends a stream iteration cleanly rather than propagating. OK and ERR_UNKNOWN have no dedicated subclass; ERR_UNKNOWN raises the base MediusError.

Status
MemberValueMemberValue
OK0ERR_DISCONNECTED6
ERR_IO1ERR_FRAME_TOO_LONG7
ERR_NOT_FOUND2ERR_FLASH_TOOL8
ERR_NO_REPLY3ERR_INVALID_ARG9
ERR_BAD_PROTO_VER4ERR_PANIC10
ERR_QUERY_TIMEOUT5ERR_UNKNOWN11