Skip to content
All topics · Text entry

Text entry

How a work takes typed text: its own field and the device's own keyboard, never a control, and what the player does while the field has the focus.

0.7 Text entry

A work may take typed text on a computer and on a phone: a name for a score, a line of chat, a search, an editor. The controller stays the Playspace set; letters as game controls are still over it. Text is the work's own field and the device's own keyboard, never a control: there is no SDK call and no manifest entry for it.

  • Use your own field. An <input> of a type that takes text (text, search, email, url, password, number, tel, or no type), a <textarea>, or a contenteditable element, on your own page and in your own style. A range, a checkbox or a select is not a text field.

  • On a phone, focus it from a touch. iOS raises the keyboard only for a focus inside a person's touch: a field the person taps, or your field.focus() called in the touch's own handler. A focus() from a timer, after an await or at load raises no keyboard (and the player keeps its controls shown for it). On a computer a focus at load is fine.

  • Give it a maxlength. The cap is the field's own, which the browser applies to typing and to paste and which never breaks a composed character: a name 24, a line 280, a text area 2,000. Nothing caps it for you.

  • Say what Enter does with enterkeyhint (done for a name, send for a chat line, search for a search) and answer Enter yourself (submit, send, a new line); the player does nothing with it.

  • A name is not a sentence. On a name field set autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false": iOS autocorrected "wasd" to "Wash" with none of them.

  • Let it go when done. On submit call field.blur(), so the keyboard closes and the player's controls come back (hiding or removing the focused field does the same).

  • Put the field in the top half of the screen. Sideways the phone's keyboard covers about half the height; a field low on the screen is pushed out of view or sits under the keys.

  • Never read letters with a window keydown listener for a name or a line: read the field's value (or its input event). A window listener also hears W A S D while the person types; where your play moves on keys, check the event's target first (if (e.target.closest("input, textarea, [contenteditable]")) return;).

What the player does while your field has the focus.

A computerA phone
KeysEvery key goes to your field as typed; nothing of the set is translated.The phone's own keyboard types.
Our controlsThe controls picture is hidden (from then on it shows the text field too; back for 3 s when the focus leaves).The stick, A, B and the pill are hidden and every key they held is let go (when the focus followed a touch); back when the focus leaves.
A touch or click elsewhereThe browser's own.The touch reaches your work first (your Continue's click reads the field), then the field is let go (blurred) if it still has the focus; a touch in the small box around the field (an editor's own buttons) keeps it.
EscThe first Esc is yours; if your field still has the focus after your handlers ran and you did not prevent it, the player lets it go (never during a composition). The next Esc is your menu key as always.The keyboard's own Done or hide key.
The pausePausing lets the field go.The same.
Buddy (autoplay)Never starts while a field has the focus and presses no key then; a key or touch on a field is never spent by a "fresh" hand-over.The same.

Our runtime never reads, records or sends what is typed: a key typed in a field is not counted in the runtime's keyed, and the player is told only that a field has the focus (typing, on or off). Keep the field in your own page (an open shadow root is fine): one inside a closed shadow root or an <iframe> of your own is not seen as a field, so the player's controls stay up and its keys may be counted as keys.

The same text, plain, for an agent: /sdk/docs/text.md