Output events and state
Enable WebSocket Server and Allow WebSocket Outputs in Inputs → WebSocket & MCP. Enable output after switching on WebSocket or MCP, because those actions reset the output option. Normal output runs at approximately 30 updates per second; Full speed removes that delay.
Receive changes
Section titled “Receive changes”{"type":"EVENTS","events":[{"type":"button","code":"A","value":true},{"type":"axis","code":"leftX","value":0.5}]}EVENTS.events contains only changed values. Apply each event to your local state; do not replace the whole state with the batch. Each event has type, code and a boolean or numeric value.
| Event types | What they describe |
|---|---|
button, axis, trigger | Gamepad output; stick-direction buttons may have numeric values |
keyboard, mouseButton | Key and mouse-button output state |
There is no initial batch or replay after connecting. Values have two-decimal precision, and numeric changes are emitted only when the difference exceeds 0.01. Settings, absolute cursor movement and scroll impulses are not part of this stream. These messages describe PlayAbility’s output state, not confirmation that a game received an action.
Read the gamepad state
Section titled “Read the gamepad state”Send {"type":"getState"}. The lowercase spelling matters. The decoded response looks like this:
{"type":"state","data":{"buttons":{"A":true},"axes":{"leftX":0.5},"triggers":{}}}Only non-neutral values are present. Omitted buttons are false; omitted numeric directions, axes and triggers are 0. Keyboard and mouse state are not included. An entirely neutral snapshot has three empty objects.
The response currently uses two JSON encoding layers. Decode an optional second layer so the same parser handles all message types:
function decodeMessage(text) { const value = JSON.parse(text); return typeof value === 'string' ? JSON.parse(value) : value;}Handle the stream
Section titled “Handle the stream”Both EVENTS and state are broadcasts to connected clients. A getState response can therefore arrive even when another client requested it. There is no separate subscription command, sequence number or timestamp.
Dispatch by type: command responses and output events share one connection. For the three gamepad sections, use the snapshot as your starting state, then apply changes. A complete keyboard/mouse snapshot and a perfectly synchronized replay are not available.
See the client examples and the command reference.