InputMapRebinder

Entityceramic.InputMapRebinder (Class)

A utility class for rebinding input mappings at runtime.

InputMapRebinder provides a user-friendly way to change input bindings by listening for input and automatically binding it to the specified action. This is commonly used in game settings menus to let players customize controls.

Features:

  • Listen for any input type (keyboard, gamepad button, gamepad axis)
  • Support for cancellation (ESC key or SELECT button by default)
  • Configurable conditions for filtering valid inputs
  • Events for tracking rebind operations
  • Option to preserve or replace existing bindings

Example usage:

var rebinder = new InputMapRebinder<Action>();

// Rebind jump action - will listen for next input
rebinder.rebind(inputMap, Action.JUMP);

// Listen for rebind completion
rebinder.onAfterRebindAny(this, (map, action) -> {
    trace('Rebound action: ' + action);
});

// Add conditions to filter inputs
rebinder.keyCondition = (action, key) -> {
    // Don't allow binding F1-F12 keys
    return key.keyCode < KeyCode.F1 || key.keyCode > KeyCode.F12;
};

Instance Members

axisToButtonDeadZone: Float

The dead zone threshold for converting analog axis movement to button presses. When binding an axis as a button, the axis must exceed this value to register. Default: 0.25 (25% of axis range)


cancelButton: GamepadButton

The gamepad button that cancels the rebind operation. Default: GamepadButton.SELECT


cancelKeyCode: KeyCode

The keyboard key that cancels the rebind operation. Default: KeyCode.ESCAPE


keyCondition(action: ceramic.InputMapRebinder.T, key: Key): Bool

Optional condition function to filter keyboard inputs during rebinding. Return false to reject the input, true to accept it. If null, all keyboard inputs are accepted (except cancel key).

Name Type
action ceramic.InputMapRebinder.T
key Key
Returns
Bool

gamepadButtonCondition(action: ceramic.InputMapRebinder.T, gamepadId: Int, button: GamepadButton): Bool

Optional condition function to filter gamepad button inputs during rebinding. Return false to reject the input, true to accept it. If null, all gamepad buttons are accepted (except cancel button).

Name Type
action ceramic.InputMapRebinder.T
gamepadId Int
button GamepadButton
Returns
Bool

gamepadAxisCondition(action: ceramic.InputMapRebinder.T, gamepadId: Int, axis: GamepadAxis, value: Float): Bool

Optional condition function to filter gamepad axis inputs during rebinding. Return false to reject the input, true to accept it. If null, all gamepad axes are accepted.

Name Type
action ceramic.InputMapRebinder.T
gamepadId Int
axis GamepadAxis
value Float
Returns
Bool

gamepadAxisToButtonCondition(action: ceramic.InputMapRebinder.T, gamepadId: Int, axis: GamepadAxis, value: Float): Bool

Optional condition function to filter gamepad axis-to-button conversions during rebinding. Return false to reject the input, true to accept it. If null, all gamepad axis movements exceeding the dead zone are accepted.

Name Type
action ceramic.InputMapRebinder.T
gamepadId Int
axis GamepadAxis
value Float
Returns
Bool

rebind(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T, ?removeExisting: Bool = true): Void

Starts listening for input to rebind the specified action. The rebinder will listen for keyboard, gamepad buttons, and gamepad axes simultaneously and bind the first valid input received.

Name Type Default Description
inputMap InputMap<ceramic.InputMapRebinder.T> The input map to modify
action ceramic.InputMapRebinder.T The action to rebind
removeExisting Bool true If true, removes existing bindings before adding the new one

new(): Void

Private Members

keyDownListener(key: Key): Void
Name Type
key Key

gamepadButtonListener(gamepadId: Int, button: GamepadButton): Void
Name Type
gamepadId Int
button GamepadButton

gamepadAxisListener(gamepadId: Int, axis: GamepadAxis, value: Float): Void
Name Type
gamepadId Int
axis GamepadAxis
value Float

gamepadAxisToButtonListener(gamepadId: Int, axis: GamepadAxis, value: Float): Void
Name Type
gamepadId Int
axis GamepadAxis
value Float

cancel(): Void

emitBeforeRebindAny(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T): Void

Triggered before any input is rebound, regardless of input type. @event beforeRebindAny

Name Type Description
inputMap InputMap<ceramic.InputMapRebinder.T> The input map being modified
action ceramic.InputMapRebinder.T The action being rebound

emitAfterRebindAny(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T): Void

Triggered after any input is successfully rebound, regardless of input type. @event afterRebindAny

Name Type Description
inputMap InputMap<ceramic.InputMapRebinder.T> The input map that was modified
action ceramic.InputMapRebinder.T The action that was rebound

isMatchingGamepad(inputMap: InputMap<ceramic.InputMapRebinder.T>, gamepadId: Int): Bool
Name Type
inputMap InputMap<ceramic.InputMapRebinder.T>
gamepadId Int
Returns
Bool

emitBeforeRebindKey(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T, key: Key): Void

Triggered before a keyboard key is bound to an action. @event beforeRebindKey

Name Type Description
inputMap InputMap<ceramic.InputMapRebinder.T> The input map being modified
action ceramic.InputMapRebinder.T The action being rebound
key Key The keyboard key being bound

emitAfterRebindKey(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T, key: Key): Void

Triggered after a keyboard key is successfully bound to an action. @event afterRebindKey

Name Type Description
inputMap InputMap<ceramic.InputMapRebinder.T> The input map that was modified
action ceramic.InputMapRebinder.T The action that was rebound
key Key The keyboard key that was bound

registerKeyListener(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T, ?removeExisting: Bool = true): Void
Name Type Default
inputMap InputMap<ceramic.InputMapRebinder.T>
action ceramic.InputMapRebinder.T
removeExisting Bool true

removeKey(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T): Void
Name Type
inputMap InputMap<ceramic.InputMapRebinder.T>
action ceramic.InputMapRebinder.T

rebindKey(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T, key: Key, ?removeExisting: Bool = true): Void
Name Type Default
inputMap InputMap<ceramic.InputMapRebinder.T>
action ceramic.InputMapRebinder.T
key Key
removeExisting Bool true

emitBeforeRebindGamepadButton(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T, button: GamepadButton): Void

Triggered before a gamepad button is bound to an action. @event beforeRebindGamepadButton

Name Type Description
inputMap InputMap<ceramic.InputMapRebinder.T> The input map being modified
action ceramic.InputMapRebinder.T The action being rebound
button GamepadButton The gamepad button being bound

emitAfterRebindGamepadButton(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T, button: GamepadButton): Void

Triggered after a gamepad button is successfully bound to an action. @event afterRebindGamepadButton

Name Type Description
inputMap InputMap<ceramic.InputMapRebinder.T> The input map that was modified
action ceramic.InputMapRebinder.T The action that was rebound
button GamepadButton The gamepad button that was bound

registerGamepadButtonListener(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T, ?removeExisting: Bool = true): Void
Name Type Default
inputMap InputMap<ceramic.InputMapRebinder.T>
action ceramic.InputMapRebinder.T
removeExisting Bool true

removeGamepadButton(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T): Void
Name Type
inputMap InputMap<ceramic.InputMapRebinder.T>
action ceramic.InputMapRebinder.T

rebindGamepadButton(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T, button: GamepadButton, ?removeExisting: Bool = true): Void
Name Type Default
inputMap InputMap<ceramic.InputMapRebinder.T>
action ceramic.InputMapRebinder.T
button GamepadButton
removeExisting Bool true

emitBeforeRebindGamepadAxis(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T, axis: GamepadAxis): Void

Triggered before a gamepad axis is bound to an axis action. @event beforeRebindGamepadAxis

Name Type Description
inputMap InputMap<ceramic.InputMapRebinder.T> The input map being modified
action ceramic.InputMapRebinder.T The axis action being rebound
axis GamepadAxis The gamepad axis being bound

emitAfterRebindGamepadAxis(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T, axis: GamepadAxis): Void

Triggered after a gamepad axis is successfully bound to an axis action. @event afterRebindGamepadAxis

Name Type Description
inputMap InputMap<ceramic.InputMapRebinder.T> The input map that was modified
action ceramic.InputMapRebinder.T The axis action that was rebound
axis GamepadAxis The gamepad axis that was bound

registerGamepadAxisListener(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T, ?removeExisting: Bool = true): Void
Name Type Default
inputMap InputMap<ceramic.InputMapRebinder.T>
action ceramic.InputMapRebinder.T
removeExisting Bool true

removeGamepadAxis(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T): Void
Name Type
inputMap InputMap<ceramic.InputMapRebinder.T>
action ceramic.InputMapRebinder.T

rebindGamepadAxis(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T, axis: GamepadAxis, value: Float, removeExisting: Bool): Void
Name Type
inputMap InputMap<ceramic.InputMapRebinder.T>
action ceramic.InputMapRebinder.T
axis GamepadAxis
value Float
removeExisting Bool

emitBeforeRebindGamepadAxisToButton(InputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T, axis: GamepadAxis): Void

Triggered before a gamepad axis is bound to a button action (axis-to-button conversion). @event beforeRebindGamepadAxisToButton

Name Type Description
InputMap InputMap<ceramic.InputMapRebinder.T> The input map being modified
action ceramic.InputMapRebinder.T The button action being rebound
axis GamepadAxis The gamepad axis being bound as a button

emitAfterRebindGamepadAxisToButton(InputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T, axis: GamepadAxis): Void

Triggered after a gamepad axis is successfully bound to a button action. @event afterRebindGamepadAxisToButton

Name Type Description
InputMap InputMap<ceramic.InputMapRebinder.T> The input map that was modified
action ceramic.InputMapRebinder.T The button action that was rebound
axis GamepadAxis The gamepad axis that was bound as a button

registerGamepadAxisToButtonListener(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T, ?removeExisting: Bool = true): Void
Name Type Default
inputMap InputMap<ceramic.InputMapRebinder.T>
action ceramic.InputMapRebinder.T
removeExisting Bool true

removeGamepadAxisToButton(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T): Void
Name Type
inputMap InputMap<ceramic.InputMapRebinder.T>
action ceramic.InputMapRebinder.T

rebindGamepadAxisToButton(inputMap: InputMap<ceramic.InputMapRebinder.T>, action: ceramic.InputMapRebinder.T, axis: GamepadAxis, value: Float, removeExisting: Bool): Void
Name Type
inputMap InputMap<ceramic.InputMapRebinder.T>
action ceramic.InputMapRebinder.T
axis GamepadAxis
value Float
removeExisting Bool

Metadata

Name Parameters
:build ceramic.macros.EntityMacro.buildForCompletion()
:autoBuild ceramic.macros.EntityMacro.buildForCompletion()
:build tracker.macros.EventsMacro.build()
:autoBuild tracker.macros.EventsMacro.build()