Skip to main content

Input

API for input handling.

Functions

Input.bindButton

Binds an action to the given button.

Input.bindButton(button: Mouse.Button | Keyboard.Key): number

Parameters

NameTypeDefault ValueDescription
buttonMouse.Button | Keyboard.KeyRequiredThe button to bind the action to.

Returns

NameTypeDescription
actionIdnumberThe action ID that the action is bound to.

Input.bindAxis

Binds an action to the given axis.

Input.bindAxis(axis: AxisBinding): number

Parameters

NameTypeDefault ValueDescription
axisAxisBindingRequiredThe axis to bind the action to.

Returns

NameTypeDescription
actionIdnumberThe action ID that the action is bound to.

Input.bindAxis2d

Binds an action to the given 2D axis.

Input.bindAxis2d(axis: AxisBinding2d): number

Parameters

NameTypeDefault ValueDescription
axisAxisBinding2dRequiredThe 2D axis to bind the action to.

Returns

NameTypeDescription
actionIdnumberThe action ID that the action is bound to.

Input.wasPressedThisFrame

Returns whether the action was pressed this frame. Always returns false when given an axis.

Input.wasPressedThisFrame(actionId: number): boolean

Parameters

NameTypeDefault ValueDescription
actionIdnumberRequiredThe action ID to check.

Returns

NameTypeDescription
pressedbooleanWhether the action was pressed this frame. Always returns false when given an axis.

Input.wasReleasedThisFrame

Returns whether the action was released this frame. Always returns false when given an axis.

Input.wasReleasedThisFrame(actionId: number): boolean

Parameters

NameTypeDefault ValueDescription
actionIdnumberRequiredThe action ID to check.

Returns

NameTypeDescription
releasedbooleanWhether the action was released this frame. Always returns false when given an axis.

Input.isHeld

Returns whether the action is held. Always returns false when given an axis.

Input.isHeld(actionId: number): boolean

Parameters

NameTypeDefault ValueDescription
actionIdnumberRequiredThe action ID to check.

Returns

NameTypeDescription
heldbooleanWhether the action is held.

Input.readAxis

Reads the value of the given axis.

Input.readAxis(actionId: number): number

Parameters

NameTypeDefault ValueDescription
actionIdnumberRequiredThe action ID to read.

Returns

NameTypeDescription
valuenumberThe value of the axis.

Input.readAxis2d

Reads the value of the given 2D axis.

Input.readAxis2d(actionId: number): number, number

Parameters

NameTypeDefault ValueDescription
actionIdnumberRequiredThe action ID to read.

Returns

NameTypeDescription
xnumberThe x-axis value.
ynumberThe y-axis value.

Input.addButtonPressListener

Adds a listener for action press events.

Input.addButtonPressListener(actionId: number, callback: function)

Parameters

NameTypeDefault ValueDescription
actionIdnumberRequiredThe action ID to listen for.
callbackfunctionRequiredThe callback to use.

Input.removeButtonPressListener

Removes a listener for action press events.

Input.removeButtonPressListener(actionId: number, callback: function)

Parameters

NameTypeDefault ValueDescription
actionIdnumberRequiredThe action ID to remove the listener from.
callbackfunctionRequiredThe callback to remove.

Input.addButtonReleaseListener

Adds a listener for action release events.

Input.addButtonReleaseListener(actionId: number, callback: function)

Parameters

NameTypeDefault ValueDescription
actionIdnumberRequiredThe action ID to listen for.
callbackfunctionRequiredThe callback to use.

Input.removeButtonReleaseListener

Removes a listener for action release events.

Input.removeButtonReleaseListener(actionId: number, callback: function)

Parameters

NameTypeDefault ValueDescription
actionIdnumberRequiredThe action ID to remove the listener from.
callbackfunctionRequiredThe callback to remove.

Input.addEventListener

Adds an event listener. A list of events can be found here.

Input.addEventListener(eventType: string, callback: function): function

Parameters

NameTypeDefault ValueDescription
eventTypestringRequiredThe event to listen for.
callbackfunctionRequiredThe callback to use.

Returns

NameTypeDescription
callbackfunctionThe callback that was registered.

Input.removeEventListener

Removes an event listener.

Input.removeEventListener(eventType: string, callback: function)

Parameters

NameTypeDefault ValueDescription
eventTypestringRequiredThe event to remove the listener from.
callbackfunctionRequiredThe callback to remove.

Types

AxisBinding2d

A binding to two axes.

type AxisBinding2d = { x: DigitalAxis | Mouse.Axis, y: DigitalAxis | Mouse.Axis, isNormalised: boolean? }

Properties

FieldTypeDescription
xDigitalAxis | Mouse.AxisThe x-axis binding.
yDigitalAxis | Mouse.AxisThe y-axis binding.
isNormalisedboolean?Whether the axis is normalized. Defaults to true.

AxisBinding

A binding to an axis.

type AxisBinding = { axis: DigitalAxis | Mouse.Axis, isNormalised: boolean? }

Properties

FieldTypeDescription
axisDigitalAxis | Mouse.AxisThe axis binding.
isNormalisedboolean?Whether the axis is normalized. Defaults to true.

DigitalAxis

A digital axis.

type DigitalAxis = { increase: Mouse.Button | Keyboard.Key, decrease: Mouse.Button | Keyboard.Key }

Properties

FieldTypeDescription
increaseMouse.Button | Keyboard.KeyThe button that increases the axis value.
decreaseMouse.Button | Keyboard.KeyThe button that decreases the axis value.

Events

"press"

Fired when an action is pressed.

Input.addEventListener("press", function(actionId) end)

Parameters

NameTypeDescription
actionIdnumberThe action ID that was pressed.

"release"

Fired when an action is released.

Input.addEventListener("release", function(actionId) end)

Parameters

NameTypeDescription
actionIdnumberThe action ID that was released.