Specialized components
Input and interaction system
Input source
10 min
overview the input source component is the foundation of the ir engine's input and interaction system it serves as the primary data container for raw input from physical or emulated devices connected to the application each input source represents a specific input device and maintains up to date information about its current state input source types the system supports various input device types, each represented by its own input source keyboard captures key presses and releases mouse tracks button clicks, movement, and scroll actions gamepad monitors button presses and analog stick positions xr controllers handles vr/ar controller input including buttons, triggers, and spatial positioning technical implementation in the ir engine, input sources are implemented through the inputsourcecomponent this component is attached to entities that represent input devices within the ecs architecture inputsourcecomponent structure the inputsourcecomponent contains several key properties button states current status of all buttons on the device (pressed, released, etc ) axis values position data for analog inputs like joysticks or triggers raycaster for pointing devices, provides an invisible ray for targeting objects in 3d space device specific data additional information relevant to particular device types code example // from components/inputsourcecomponent tsx export const inputsourcecomponent = definecomponent({ name 'inputsourcecomponent', schema { source s type\<xrinputsource>({ default {} as xrinputsource }), buttons s type\<readonly\<buttonstatemap\<typeof defaultbuttonbindings>>>({ default {} }), raycaster s class(() => new raycaster()), intersections s array(/ /) // additional fields omitted for brevity }, onset (entity, component, args) => { // initialization logic when component is added to an entity // sets up default values or uses provided source data // may add related components like xrhandcomponent if needed } // additional methods omitted for brevity }); input source lifecycle the creation and management of input sources follow a specific process device connection a physical or emulated input device becomes available entity creation the system creates an entity to represent the device component attachment an inputsourcecomponent is attached to the entity state initialization default values are set based on the device type continuous updates the clientinputsystem regularly updates the component with the latest device state sequencediagram participant player participant device participant os as operating system participant engine as ir engine (clientinputsystem) participant entity participant isc as inputsourcecomponent player >>device connects device device >>os registers with system os >>engine device connection event engine >>entity create entity for device engine >>isc create inputsourcecomponent engine >>entity attach component to entity note over engine,isc component ready to receive input data system integration the inputsourcecomponent interacts with several other systems clientinputsystem updates the component with the latest hardware input data clientinputhooks sets up listeners for different device types usenonspatialinputsources for keyboard and mouse usegamepadinputsources for standard gamepads usexrinputsources for xr controllers the clientinputsystem performs these key operations each frame updates pointer based input sources using raycasting updates xr controller positions and orientations calls clientinputfunctions updategamepadinput to refresh button and axis states practical usage developers rarely need to create inputsourcecomponent instances manually, as the engine automatically handles this for standard input devices however, understanding the component's structure is essential when implementing custom input devices creating advanced input handling logic debugging input related issues next steps with an understanding of how raw input data is captured and stored in input sources, the next chapter explores how this data is structured through standardized button and axis states next button and axis state docid 9thsqup1foiozxngefulw