Input
API for input handling.
Functions
Input.bindButton
Binds an action to the given button.
Input.bindButton(button: Mouse.Button | Keyboard.Key): number
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
button | Mouse.Button | Keyboard.Key | Required | The button to bind the action to. |
Returns
Name | Type | Description |
---|---|---|
actionId | number | The action ID that the action is bound to. |
Input.bindAxis
Binds an action to the given axis.
Input.bindAxis(axis: AxisBinding): number
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
axis | AxisBinding | Required | The axis to bind the action to. |
Returns
Name | Type | Description |
---|---|---|
actionId | number | The action ID that the action is bound to. |
Input.bindAxis2d
Binds an action to the given 2D axis.
Input.bindAxis2d(axis: AxisBinding2d): number
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
axis | AxisBinding2d | Required | The 2D axis to bind the action to. |
Returns
Name | Type | Description |
---|---|---|
actionId | number | The 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
Name | Type | Default Value | Description |
---|---|---|---|
actionId | number | Required | The action ID to check. |
Returns
Name | Type | Description |
---|---|---|
pressed | boolean | Whether 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
Name | Type | Default Value | Description |
---|---|---|---|
actionId | number | Required | The action ID to check. |
Returns
Name | Type | Description |
---|---|---|
released | boolean | Whether 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
Name | Type | Default Value | Description |
---|---|---|---|
actionId | number | Required | The action ID to check. |
Returns
Name | Type | Description |
---|---|---|
held | boolean | Whether the action is held. |
Input.readAxis
Reads the value of the given axis.
Input.readAxis(actionId: number): number
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
actionId | number | Required | The action ID to read. |
Returns
Name | Type | Description |
---|---|---|
value | number | The value of the axis. |
Input.readAxis2d
Reads the value of the given 2D axis.
Input.readAxis2d(actionId: number): number, number
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
actionId | number | Required | The action ID to read. |
Returns
Name | Type | Description |
---|---|---|
x | number | The x-axis value. |
y | number | The y-axis value. |
Input.addButtonPressListener
Adds a listener for action press events.
Input.addButtonPressListener(actionId: number, callback: function)
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
actionId | number | Required | The action ID to listen for. |
callback | function | Required | The callback to use. |
Input.removeButtonPressListener
Removes a listener for action press events.
Input.removeButtonPressListener(actionId: number, callback: function)
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
actionId | number | Required | The action ID to remove the listener from. |
callback | function | Required | The callback to remove. |
Input.addButtonReleaseListener
Adds a listener for action release events.
Input.addButtonReleaseListener(actionId: number, callback: function)
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
actionId | number | Required | The action ID to listen for. |
callback | function | Required | The callback to use. |
Input.removeButtonReleaseListener
Removes a listener for action release events.
Input.removeButtonReleaseListener(actionId: number, callback: function)
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
actionId | number | Required | The action ID to remove the listener from. |
callback | function | Required | The 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
Name | Type | Default Value | Description |
---|---|---|---|
eventType | string | Required | The event to listen for. |
callback | function | Required | The callback to use. |
Returns
Name | Type | Description |
---|---|---|
callback | function | The callback that was registered. |
Input.removeEventListener
Removes an event listener.
Input.removeEventListener(eventType: string, callback: function)
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
eventType | string | Required | The event to remove the listener from. |
callback | function | Required | The callback to remove. |
Types
AxisBinding2d
A binding to two axes.
type AxisBinding2d = { x: DigitalAxis | Mouse.Axis, y: DigitalAxis | Mouse.Axis, isNormalised: boolean? }
Properties
Field | Type | Description |
---|---|---|
x | DigitalAxis | Mouse.Axis | The x-axis binding. |
y | DigitalAxis | Mouse.Axis | The y-axis binding. |
isNormalised | boolean? | Whether the axis is normalized. Defaults to true . |
AxisBinding
A binding to an axis.
type AxisBinding = { axis: DigitalAxis | Mouse.Axis, isNormalised: boolean? }
Properties
Field | Type | Description |
---|---|---|
axis | DigitalAxis | Mouse.Axis | The axis binding. |
isNormalised | boolean? | 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
Field | Type | Description |
---|---|---|
increase | Mouse.Button | Keyboard.Key | The button that increases the axis value. |
decrease | Mouse.Button | Keyboard.Key | The button that decreases the axis value. |
Events
"press"
Fired when an action is pressed.
Input.addEventListener("press", function(actionId) end)
Parameters
Name | Type | Description |
---|---|---|
actionId | number | The action ID that was pressed. |
"release"
Fired when an action is released.
Input.addEventListener("release", function(actionId) end)
Parameters
Name | Type | Description |
---|---|---|
actionId | number | The action ID that was released. |