useInput()
Composable that returns the global InputService registered by InputPlugin.
ts
function useInput(): InputServiceMust be called inside an active engine context (defineSystem(), engine.run(), or a plugin lifecycle hook).
Throws GwenPluginNotFoundError if @gwenjs/input is not registered.
Example
ts
import { defineActor } from '@gwenjs/core/actor'
import { useInput } from '@gwenjs/input'
import { Jump } from './actions'
export const PlayerActor = defineActor(PlayerPrefab, () => {
const input = useInput()
onUpdate(() => {
const p1 = input.player(0)
const jump = p1.action(Jump)
if (jump.isJustTriggered) applyJumpForce()
})
})For most per-action reads, prefer useAction(ref) directly. Use useInput() when you need access to the full InputService — for example, to iterate over all players, access raw devices, or manage recording.
usePlayer
ts
function usePlayer(index?: number): PlayerInputShorthand for useInput().player(index). Returns the PlayerInput for the given zero-based player slot. Defaults to player 0.
ts
const p2 = usePlayer(1)
const jump = p2.action(Jump)Throws
GwenPluginNotFoundError— if@gwenjs/inputis not registered.RangeError— ifindexis out of bounds.