game-input

Owns native buttons with data-action=start|pause|restart|left|right|up|down|fire. Arrow keys/WASD move, Space fires, P/Escape pause. Held pointers support multi-touch. Discovers the first available gamepad at rest and polls axes/buttons every 50 ms. Disconnect hands ownership to the next connected pad or native controls. Modified keys and text entry remain native.

Examples

Direction and fire

Hold a direction or press an arrow key with a control focused. Press Fire to send a command. A connected controller uses the same events.

Direction and fire HTML
<game-input deadzone="0.18" fire-button="0">
	<div role="group" aria-label="Flight input example">
		<button type="button" data-action="left">Left</button>
		<button type="button" data-action="right">Right</button>
		<button type="button" data-action="fire">Fire</button>
	</div>
</game-input>

Start, pause, and restart

Send lifecycle commands through native buttons. A world interprets these commands during play.

Start, pause, and restart HTML
<game-input>
	<button type="button" data-action="start">Start</button>
	<button type="button" data-action="pause">Pause or resume</button>
	<button type="button" data-action="restart">Restart</button>
</game-input>

API

Attributes
NameType or defaultBehavior
deadzone number Default 0.18 Stick deadzone, clamped to 0–0.9. Values outside it are rescaled.
fire-button number Default 0 Gamepad fire-button index, integer 0–31. Right trigger also fires.
Emitted events
NameType or defaultBehavior
game-input CustomEvent<{ x: number, y: number, fire: boolean, source: string, command?: string }> Bubbles and is composed. Emitted when normalized axes, fire state, source or command change. Axes are -1–1. Commands match button actions.
game-controller-change CustomEvent<{ index: number, connected: boolean, name: string, mapping: string }> Bubbles and is composed. Reports player-one controller acquisition or loss. index=-1 means native controls. Browser standard mapping uses axes 0/1, D-pad 12–15, trigger 7 and Start 9.

Listened-for events

None.

CSS custom properties

None.

Markup hooks
NameType or defaultBehavior
data-action On a button, names an input command. Use start, pause, restart, left, right, up, down, or fire. A world treats pause as a toggle.

View the Game Kit manifest