Skip to content

@carrot/input ​

ts

Browser input system for the Carrot engine. Raw device access (keyboard, mouse, touch, gamepad) plus a full action mapping layer for production game input.

Usage ​

ts
import { Input } from '@carrot/input';

const input = new Input(document.body);

// In your game loop
input.update(delta);

Contents ​

  • Raw devices - keyboard, mouse, touch, gamepads with unified polling API (getButton, getAxis, getButtonDown, getButtonHold, etc.)
  • Action mapping - named actions with physical-to-virtual translation, easing, ASR envelopes, and aggregation
  • Contexts - switchable action groups with push/pop frame stack for overlays
  • Chords - multi-signal combinations as virtual Chord:* signals
  • Gamepad detection - family/model identification for Xbox, PlayStation, Switch, and Steam controllers
  • Vibration - rumble, pulse, per-frame driven haptics, and curve-based animation
  • Glyphs - signal-to-icon resolution for device-aware UI prompts
  • Profiles - JSON-serializable action/binding schemas with load, save, and merge
  • Multiplayer - per-player input isolation with independent device assignment

Dependencies ​

  • @carrot/signals - event system
  • @carrot/logging - optional logging
  • @carrot/maths - easing functions

Build ​

bash
npm run build

@carrot/input - Contents ​

Import: import { Input } from '@carrot/input';

Core ​

Input · InputSignalEvent · InputSignalType

Devices ​

Base ​

InputDevice · InputDevices · InputDeviceCategory · InputScheme · InputDeviceDescriptor · buildDescriptor · schemeFromCategory

Keyboard ​

InputDeviceKeyboard · Keyboard · KeyboardMedia · KeyboardBrowser · KeyboardSystem · KeyboardRare

Mouse ​

InputDeviceMouse · Mouse

Touch ​

InputDeviceTouch · Touch

Gamepads ​

InputDeviceGamepad · InputDeviceGamepads · InputDeviceGamepadFamily · InputDeviceGamepadModel · InputDeviceGamepadVibration · InputDeviceCapability · hasCapability · capabilitiesForModel

Signal constants: GamepadGeneric · GamepadXbox · GamepadPlaystation · GamepadSwitch

Actions ​

InputActions · InputAction · InputActionBinding · InputActionType

Binding Config ​

TypePurpose
InputBindingSpecFlexible binding (string or config object)
EasingSpecEasing type or custom function
AxisToButtonConfigThreshold-based axis → button conversion
ButtonToAxisConfigASR envelope for button → axis conversion
DirectConfigDirect scaling config

Contexts ​

InputContext · InputContexts · InputContextFrame

Chords ​

InputChordManager · ChordConstituent

Glyphs ​

InputGlyphs · GlyphDescriptor

Profiles ​

InputProfileLoader · InputProfile · InputProfileBinding · InputProfileAction · InputProfileContext

Players ​

InputPlayer

Types ​

InputButtonState · TouchState · InputDeviceChangedEvent · InputContextFrameOptions · InputContextQueryOptions · InputActionOptions · InputActionEvent · InputDeviceCapabilities · GamepadDescriptorSource

Carrot