# Protocol: input

The `input` commands a program sends to a running game, as the engine describes them: what each takes, what it answers and what it does. Back to [all commands](../protocol-commands.md).

## input.set

`input.set {player?: integer, action?: text, value?: number, actions?: record} -> {player: integer, action: text, value: number, actions: record}` · write

Holds one player's value for an input action until it is set again. With actions in place of action and value, holds several at once, as a stretch of game.try's inputs or a project's recording writes them: {player?, actions: {move_x: 1, jump: 1}}.

| Parameters | Type | Meaning |
| --- | --- | --- |
| `player?` | integer | The player, counting from 0. Left out: 0. |
| `action?` | text | An input action name, as game.info lists them. With value; or give actions. |
| `value?` | number | An axis from -1 to 1, or a button: 1 held, 0 released. A value outside -1 to 1 is refused, but for an action bound to the pointer's motion (MouseWheel, MouseWheelX, MouseDeltaX, MouseDeltaY), which takes any finite value: notches, or pixels of the frame. |
| `actions?` | record | In place of action and value: each action's name and its value, as game.try's inputs write a stretch ({move_x: 1, jump: 1}), each held as value would be. All are checked before any is held. |

| Result | Type | Meaning |
| --- | --- | --- |
| `player` | integer | The player. |
| `action` | text | The action; with actions, the last of them by name. |
| `value` | number | The value now held; with actions, the last one's. |
| `actions` | record | With actions: each action's value now held. null without. |

## input.capture

`input.capture {player: integer, granted: value} -> {player: integer, granted: value, asked: value}` · write

Holds whether the device holds a player's pointer captured, as recorded input: what a game reads with input.captured (Input.Captured in C#) until it is set again. What the game asked (input.capture) is world state and is answered too.

| Parameters | Type | Meaning |
| --- | --- | --- |
| `player` | integer | The player, counting from 0. |
| `granted` | value | true: the pointer is captured, as a system or a browser grants it; false: it is not. |

| Result | Type | Meaning |
| --- | --- | --- |
| `player` | integer | The player. |
| `granted` | value | What is held now. |
| `asked` | value | Whether the game asks for the player's pointer to be captured: world state, in the checksum. |

## input.keys

`input.keys {} -> {keys: [record], names: [record], pointer: record, fingers: [record]}` · read, read-only

Lists the keys the project binds to input actions, and every key name the engine knows.

| Result | Type | Meaning |
| --- | --- | --- |
| `keys` | [record] | One {action, player, key, negative, positive} per binding, as the project file writes them under [input.keys]. A binding that names a gamepad's button or stick is read from the pad with the player's number. A button has key (the action is 1 while it is down) and null for the other two; an axis has negative and positive (-1 and 1 while each is down) and null for key. A name is given as written, also one that is not a key. |
| `names` | [record] | Every key name there is, one {name, code}: name is what a project file writes ("A" to "Z", "0" to "9", "Space", "Enter", "Tab", "Escape", "Left", "Right", "Up", "Down", and the pointer's buttons "MouseLeft", "MouseRight", "MouseMiddle"; a finger on a touch screen is "MouseLeft"; a gamepad's sixteen buttons "PadA" to "PadRight"; the rest of a keyboard named as KeyboardEvent.code names it, "PageUp" to "NumpadEnter" (paging and editing keys, "F1" to "F12", "ShiftLeft" and the other modifiers by side, "CapsLock", punctuation such as "BracketLeft" and "Backquote", the number pad); then the four directions of its sticks, "PadLeftX", "PadLeftY", "PadRightX", "PadRightY", each an axis by itself with right and up as 1; and last the pointer's motion this step, axes with no end: "MouseWheel" and "MouseWheelX" (the wheel's notches, away from the person and to the right as 1), "MouseDeltaX" and "MouseDeltaY" (how far it moved in the frame's pixels, right and up)) and code is what a browser reports for that key in KeyboardEvent.code ("KeyA", "Digit0", "Space", "ArrowLeft"; a button's code is its name). |
| `pointer` | record | The {x, y, player} the project writes as pointer under [input]: the two actions that are told where the pointer (the mouse, or a finger) is, x from -1 at the frame's left edge to 1 at its right and y from -1 at its bottom to 1 at its top, and the player they are set for. null when the project names none. A client moves the pointer with input.set on those two actions. |
| `fingers` | [record] | One {region, x, y, press, player, stick, shown, label, made} per finger slot, in the order a finger looks for a free slot: the project's `fingers` under [input], or, when it writes none, the touch controls made from its actions (made true; `frost check --explain-touch` says why each). region {x, y, w, h} is the part of the frame a finger takes the slot in, in the units of the pointer's place (-1 to 1, y up); x and y are the actions that hold the slot's finger's place (either may be null), press the action that is 1 while it is down (null for a stick that has none). Empty when there are none. A client plays a finger with input.set on those actions. |

## input.history

`input.history {} -> {step: integer, seed: integer, recording: text, tuning: [record], edits: [integer]}` · read, read-only

Returns the input of every step so far in the form a project file records it, to save and replay.

| Result | Type | Meaning |
| --- | --- | --- |
| `step` | integer | How many fixed steps have run. |
| `seed` | integer | The seed the session started from; a replay needs the same one. |
| `recording` | text | The whole key as a project file writes it under `[input]`, from `recording = [` to the closing `]`, after a `saves` line when the session started from saves: paste it there as it is, or save it alone in a file for frost run --input and for `recording = "run.toml"`. With it and the seed, frost run reaches this step with this checksum, unless world.set or script.reload changed the game on the way. |
| `tuning` | [record] | One {step, name, value} per tuning value set since the game was loaded, in order; one set before the game was loaded again is at step 0. Empty for a game on the project's own values. A replay sets them again: frost run --set tuning.NAME=VALUE for those at step 0, tuning.set at its step for one set later. |
| `edits` | [integer] | The step count at each change a client made to the game that is not input (a write to the world, scene.load, saves.set, debug.evaluate), oldest first, on the line of time the game is on: one made after a snapshot that game.restore put back is not here. The recording does not hold them: a replay of it goes another way from the first of these steps on. Empty when the recording is the whole of the run. |
