Class InputMapper<THandlers>
Type Parameters
- THandlers extends Record<string, unknown>
Object type whose keys are the valid interaction type strings and values are the handler functions/objects for each interaction (e.g.
ArcRotateHandlers). Interaction types are derived asInteractionName<THandlers>.
Constructors
constructor
-
new InputMapper<THandlers extends Record<string, unknown>>(
handlers: THandlers,
createDefaultEntries?: () => InputMapEntry<InteractionName<THandlers>>[],
): InputMapper<THandlers>Creates a new InputMapper.
Type Parameters
- THandlers extends Record<string, unknown>
Object type whose keys are the valid interaction type strings and values are the handler functions/objects for each interaction (e.g.
ArcRotateHandlers). Interaction types are derived asInteractionName<THandlers>.
Parameters
- handlers: THandlers
The interaction handlers, keyed by interaction type.
OptionalcreateDefaultEntries: () => InputMapEntry<InteractionName<THandlers>>[]Optional factory that returns the default inputMap entries. Called by
resetInputMap()and during construction. When omitted, the default map is empty.
Returns InputMapper<THandlers>
- THandlers extends Record<string, unknown>
Properties
Readonlyhandlers
Interaction handlers keyed by interaction type. Override individual handlers to customize behavior without changing input mapping.
input Map
Ordered list of input-to-interaction mapping rules. First matching entry wins.
Methods
add Entry
-
Adds an entry to the inputMap at the correct position based on specificity. More specific entries (with more conditions like button, key, modifiers) are placed before less specific ones, ensuring they match first. Among equally specific entries, the new entry is placed after existing ones.
Parameters
- entry: InputMapEntry<InteractionName<THandlers>>
The entry to add
Returns void
- entry: InputMapEntry<InteractionName<THandlers>>
get Entries
-
getEntries(
source: "pointer",
interaction: InteractionName<THandlers>,
conditions?: PointerConditions,
): PointerInputMapEntry<InteractionName<THandlers>>[]Finds all inputMap entries matching the given source, interaction, and optional entry conditions. Useful for bulk updates when more than one physical input maps to the same interaction.
Parameters
- source: "pointer"
The physical input source to match
- interaction: InteractionName<THandlers>
The interaction type to match
Optionalconditions: PointerConditionsOptional entry conditions to match. Omitted condition fields are ignored.
Returns PointerInputMapEntry<InteractionName<THandlers>>[]
All matching entries, in inputMap order
- source: "pointer"
-
getEntries(
source: "wheel",
interaction: InteractionName<THandlers>,
conditions?: WheelConditions,
): WheelInputMapEntry<InteractionName<THandlers>>[]Finds all inputMap entries matching the given source, interaction, and optional entry conditions. Useful for bulk updates when more than one physical input maps to the same interaction.
Parameters
- source: "wheel"
The physical input source to match
- interaction: InteractionName<THandlers>
The interaction type to match
Optionalconditions: WheelConditionsOptional entry conditions to match. Omitted condition fields are ignored.
Returns WheelInputMapEntry<InteractionName<THandlers>>[]
All matching entries, in inputMap order
- source: "wheel"
-
getEntries(
source: "touch",
interaction: InteractionName<THandlers>,
conditions?: TouchConditions,
): TouchInputMapEntry<InteractionName<THandlers>>[]Finds all inputMap entries matching the given source, interaction, and optional entry conditions. Useful for bulk updates when more than one physical input maps to the same interaction.
Parameters
- source: "touch"
The physical input source to match
- interaction: InteractionName<THandlers>
The interaction type to match
Optionalconditions: TouchConditionsOptional entry conditions to match. Omitted condition fields are ignored.
Returns TouchInputMapEntry<InteractionName<THandlers>>[]
All matching entries, in inputMap order
- source: "touch"
-
getEntries(
source: "keyboard",
interaction: InteractionName<THandlers>,
conditions?: KeyboardConditions,
): KeyboardInputMapEntry<InteractionName<THandlers>>[]Finds all inputMap entries matching the given source, interaction, and optional entry conditions. Useful for bulk updates when more than one physical input maps to the same interaction.
Parameters
- source: "keyboard"
The physical input source to match
- interaction: InteractionName<THandlers>
The interaction type to match
Optionalconditions: KeyboardConditionsOptional entry conditions to match. Omitted condition fields are ignored.
Returns KeyboardInputMapEntry<InteractionName<THandlers>>[]
All matching entries, in inputMap order
- source: "keyboard"
-
getEntries(
source: InputSource,
interaction: InteractionName<THandlers>,
conditions?: InputConditions,
): InputMapEntry<InteractionName<THandlers>>[]Finds all inputMap entries matching the given source, interaction, and optional entry conditions. Useful for bulk updates when more than one physical input maps to the same interaction.
Parameters
- source: InputSource
The physical input source to match
- interaction: InteractionName<THandlers>
The interaction type to match
Optionalconditions: InputConditionsOptional entry conditions to match. Omitted condition fields are ignored.
Returns InputMapEntry<InteractionName<THandlers>>[]
All matching entries, in inputMap order
- source: InputSource
get Entry
-
getEntry(
source: "pointer",
interaction: InteractionName<THandlers>,
conditions?: PointerConditions,
): PointerInputMapEntry<InteractionName<THandlers>> | undefinedFinds the first inputMap entry matching the given source, interaction, and optional entry conditions. Useful for modifying entry properties (e.g. sensitivity) without rebuilding the entire inputMap.
Parameters
- source: "pointer"
The physical input source to match
- interaction: InteractionName<THandlers>
The interaction type to match
Optionalconditions: PointerConditionsOptional entry conditions to match. Omitted condition fields are ignored.
Returns PointerInputMapEntry<InteractionName<THandlers>> | undefined
The matching entry, or undefined if not found
- source: "pointer"
-
getEntry(
source: "wheel",
interaction: InteractionName<THandlers>,
conditions?: WheelConditions,
): WheelInputMapEntry<InteractionName<THandlers>> | undefinedFinds the first inputMap entry matching the given source, interaction, and optional entry conditions. Useful for modifying entry properties (e.g. sensitivity) without rebuilding the entire inputMap.
Parameters
- source: "wheel"
The physical input source to match
- interaction: InteractionName<THandlers>
The interaction type to match
Optionalconditions: WheelConditionsOptional entry conditions to match. Omitted condition fields are ignored.
Returns WheelInputMapEntry<InteractionName<THandlers>> | undefined
The matching entry, or undefined if not found
- source: "wheel"
-
getEntry(
source: "touch",
interaction: InteractionName<THandlers>,
conditions?: TouchConditions,
): TouchInputMapEntry<InteractionName<THandlers>> | undefinedFinds the first inputMap entry matching the given source, interaction, and optional entry conditions. Useful for modifying entry properties (e.g. sensitivity) without rebuilding the entire inputMap.
Parameters
- source: "touch"
The physical input source to match
- interaction: InteractionName<THandlers>
The interaction type to match
Optionalconditions: TouchConditionsOptional entry conditions to match. Omitted condition fields are ignored.
Returns TouchInputMapEntry<InteractionName<THandlers>> | undefined
The matching entry, or undefined if not found
- source: "touch"
-
getEntry(
source: "keyboard",
interaction: InteractionName<THandlers>,
conditions?: KeyboardConditions,
): KeyboardInputMapEntry<InteractionName<THandlers>> | undefinedFinds the first inputMap entry matching the given source, interaction, and optional entry conditions. Useful for modifying entry properties (e.g. sensitivity) without rebuilding the entire inputMap.
Parameters
- source: "keyboard"
The physical input source to match
- interaction: InteractionName<THandlers>
The interaction type to match
Optionalconditions: KeyboardConditionsOptional entry conditions to match. Omitted condition fields are ignored.
Returns KeyboardInputMapEntry<InteractionName<THandlers>> | undefined
The matching entry, or undefined if not found
- source: "keyboard"
-
getEntry(
source: InputSource,
interaction: InteractionName<THandlers>,
conditions?: InputConditions,
): InputMapEntry<InteractionName<THandlers>> | undefinedFinds the first inputMap entry matching the given source, interaction, and optional entry conditions. Useful for modifying entry properties (e.g. sensitivity) without rebuilding the entire inputMap.
Parameters
- source: InputSource
The physical input source to match
- interaction: InteractionName<THandlers>
The interaction type to match
Optionalconditions: InputConditionsOptional entry conditions to match. Omitted condition fields are ignored.
Returns InputMapEntry<InteractionName<THandlers>> | undefined
The matching entry, or undefined if not found
- source: InputSource
reset Input Map
-
Restores the inputMap to the default entries provided at construction time. If no factory was provided, resets to an empty array.
Returns void
resolve Interaction
-
resolveInteraction(
source: "pointer",
currentConditions?: InputConditions,
): PointerInputMapEntry<InteractionName<THandlers>> | nullResolves a physical input event to a matching inputMap entry. Iterates the inputMap in order; the first entry whose source and conditions match wins.
Parameters
- source: "pointer"
The physical input source (e.g. "pointer", "keyboard")
OptionalcurrentConditions: InputConditionsConditions to match against, specific to the source type
Returns PointerInputMapEntry<InteractionName<THandlers>> | null
The matched InputMapEntry, or null if no entry matches
- source: "pointer"
-
resolveInteraction(
source: "wheel",
currentConditions?: InputConditions,
): WheelInputMapEntry<InteractionName<THandlers>> | nullResolves a physical input event to a matching inputMap entry. Iterates the inputMap in order; the first entry whose source and conditions match wins.
Parameters
- source: "wheel"
The physical input source (e.g. "pointer", "keyboard")
OptionalcurrentConditions: InputConditionsConditions to match against, specific to the source type
Returns WheelInputMapEntry<InteractionName<THandlers>> | null
The matched InputMapEntry, or null if no entry matches
- source: "wheel"
-
resolveInteraction(
source: "touch",
currentConditions?: InputConditions,
): TouchInputMapEntry<InteractionName<THandlers>> | nullResolves a physical input event to a matching inputMap entry. Iterates the inputMap in order; the first entry whose source and conditions match wins.
Parameters
- source: "touch"
The physical input source (e.g. "pointer", "keyboard")
OptionalcurrentConditions: InputConditionsConditions to match against, specific to the source type
Returns TouchInputMapEntry<InteractionName<THandlers>> | null
The matched InputMapEntry, or null if no entry matches
- source: "touch"
-
resolveInteraction(
source: "keyboard",
currentConditions?: InputConditions,
): KeyboardInputMapEntry<InteractionName<THandlers>> | nullResolves a physical input event to a matching inputMap entry. Iterates the inputMap in order; the first entry whose source and conditions match wins.
Parameters
- source: "keyboard"
The physical input source (e.g. "pointer", "keyboard")
OptionalcurrentConditions: InputConditionsConditions to match against, specific to the source type
Returns KeyboardInputMapEntry<InteractionName<THandlers>> | null
The matched InputMapEntry, or null if no entry matches
- source: "keyboard"
-
resolveInteraction(
source: InputSource,
currentConditions?: InputConditions,
): InputMapEntry<InteractionName<THandlers>> | nullResolves a physical input event to a matching inputMap entry. Iterates the inputMap in order; the first entry whose source and conditions match wins.
Parameters
- source: InputSource
The physical input source (e.g. "pointer", "keyboard")
OptionalcurrentConditions: InputConditionsConditions to match against, specific to the source type
Returns InputMapEntry<InteractionName<THandlers>> | null
The matched InputMapEntry, or null if no entry matches
- source: InputSource
set Interaction
-
setInteraction(
source: InputSource,
conditions: InputConditions | undefined,
interaction: InteractionName<THandlers>,
): booleanSets the interaction for the input combination described by
conditions. If an existing entry maps that exact combination, itsinteractionis updated in place; otherwise a new entry is inserted via addEntry.To force an update on every matching entry use setInteractions; to address an individual entry beyond the first, look it up via getEntries and assign
entry.interactiondirectly.Parameters
- source: InputSource
The physical input source to match
- conditions: InputConditions | undefined
Conditions describing the input combination (button, modifiers, key, etc.)
- interaction: InteractionName<THandlers>
The interaction to assign / insert
Returns boolean
true (the mapping is always made effective)
- source: InputSource
set Interactions
-
setInteractions(
source: InputSource,
conditions: InputConditions | undefined,
interaction: InteractionName<THandlers>,
): numberChanges the interaction for every inputMap entry matching the given source and conditions. Useful when more than one entry maps to the same physical input (e.g. duplicate bindings, or several keys aliased to the same action) and all of them should be remapped together.
Parameters
- source: InputSource
The physical input source to match
- conditions: InputConditions | undefined
Conditions to match (button, modifiers, key, etc.). Uses the same event-resolution semantics as resolveInteraction: omitted entry condition fields are treated as wildcards and will match.
- interaction: InteractionName<THandlers>
The new interaction to assign to every matched entry
Returns number
The number of entries that were updated
- source: InputSource
Generic input-to-interaction mapper that resolves physical input events to semantic interaction types and dispatches them to typed handlers.
InputMapperis not tied to cameras — any object that needs a configurable, prioritized mapping from physical inputs (pointer, keyboard, wheel, touch) to named interactions can use it.The mapper holds an ordered
inputMaparray. WhenresolveInteractionis called, the first entry whose source and conditions match the current input wins. More specific entries (with more conditions like button, key, modifiers) should be placed before less specific ones; useaddEntryto auto-insert based on specificity.