-
class Input¶
Global input tracker. Controls use its state to update theirs.
-
key:
table<string,ControlState>¶ Current state of keyboard presses.
-
sc:
table<string,ControlState>¶ Current state of keyboard presses, as scancodes.
-
text:
table<string,ControlState>¶ Current state of text input.
-
mouse:
table<string|integer,ControlState>¶ Current state of mouse presses.
-
button:
table<string,ControlState>¶ Current state of gamepad button presses.
-
axis:
table<string,ControlState>¶ Current state of gamepad joysticks.
-
get:
InputGetter¶ Getters for other inputs.
-
staticmethod keypressed(key:
string, sc:string)¶ Handles keyboard key press events.
- Parameters:
key (
string) – The key that was pressed.sc (
string) – The scancode of the pressed key.
-
staticmethod textinput(text:
string)¶ Handles text input events.
- Parameters:
text (
string) – The text that was input.
-
staticmethod keyreleased(key:
string, sc:string)¶ Handles keyboard key release events.
- Parameters:
key (
string) – The key that was released.sc (
string) – The scancode of the released key.
-
staticmethod mousepressed(x:
number, y:number, button:number)¶ Handles mouse button press events.
- Parameters:
x (
number) – Mouse x position when pressed.y (
number) – Mouse y position when pressed.button (
number) – Mouse button that was pressed (1=left, 2=right, 3=middle).
-
staticmethod mousereleased(x:
number, y:number, button:number)¶ Handles mouse button release events.
- Parameters:
x (
number) – Mouse x position when released.y (
number) – Mouse y position when released.button (
number) – Mouse button that was released.
-
staticmethod mousemoved(x:
number, y:number)¶ Handles mouse movement events.
- Parameters:
x (
number) – New mouse x position.y (
number) – New mouse y position.
-
staticmethod wheelmoved(x:
number, y:number)¶ Handles mouse wheel movement events.
- Parameters:
x (
number) – Horizontal wheel movement.y (
number) – Vertical wheel movement.
-
staticmethod gamepadpressed(joystick:
love.joystick.Joystick, button:string)¶ Handles gamepad button press events.
- Parameters:
joystick (
love.joystick.Joystick) – The joystick object that generated the event.button (
string) – The name of the button that was pressed.
-
staticmethod gamepadreleased(joystick:
love.joystick.Joystick, button:string)¶ Handles gamepad button release events.
- Parameters:
joystick (
love.joystick.Joystick) – The joystick object that generated the event.button (
string) – The name of the button that was released.
-
staticmethod gamepadaxis(
joystick:love.joystick.Joystick,
axis_name:string,
axis_value:number
)¶ Handles gamepad axis movement events.
- Parameters:
joystick (
love.joystick.Joystick) – The joystick object that generated the event.axis_name (
string) – The name of the axis that moved (e.g., “leftx”, “lefty”, “triggerleft”).axis_value (
number) – The new axis value (-1 to 1 for sticks, 0 to 1 for triggers).
-
staticmethod hook()¶
Automatically integrates Mash with LÖVE by hooking into all the necessary input callbacks. Call this once during initialization.
-
staticmethod reset()¶
Resets all input states for the next frame. This should be called at the end of each frame (typically in love.update) to clear pressed/released flags and prepare for the next frame’s input.
-
staticmethod setThreshold(threshold:
number)¶ Sets the deadzone threshold for analog inputs.
- Parameters:
threshold (
number) – The new threshold value (0-1), default is 0.5.
-
key:
-
class InputGetter¶
Metatable for input value getters
-
_parent: {_joystickId:
integer, _mode: "both" | "joystick" | "keyboard", _transform:love.math.Transform}¶
-
mouse(self:
InputGetter, transform?:love.math.Transform): (x:number, y:number)¶ Gets the current mouse position, optionally transformed.
- Parameters:
transform? (
love.math.Transform) – Optional transform to apply (overrides instance transform).- Returns:
x (
number) – The mouse x coordinate.y (
number) – The mouse y coordinate.
-
wheel(self:
InputGetter): (x:number, y:number)¶ Gets the current mouse wheel movement.
- Returns:
x (
number) – Horizontal wheel movement.y (
number) – Vertical wheel movement.
-
left(
self:InputGetter,
joystick?:number|love.joystick.Joystick
): (x:number, y:number)¶ Gets the left analog stick position.
- Parameters:
joystick? (
number|love.joystick.Joystick) – Optional specific joystick to query- Returns:
x (
number) – The x-axis value (-1 to 1)y (
number) – The y-axis value (-1 to 1)
-
right(
self:InputGetter,
joystick?:number|love.joystick.Joystick
): (x:number, y:number)¶ Gets the right analog stick position
- Parameters:
joystick? (
number|love.joystick.Joystick) – Optional specific joystick to query- Returns:
x (
number) – The x-axis value (-1 to 1)y (
number) – The y-axis value (-1 to 1)
-
lt(
self:InputGetter,
joystick?:number|love.joystick.Joystick
):number¶ Gets the left trigger value
- Parameters:
joystick? (
number|love.joystick.Joystick) – Optional specific joystick to query- Returns:
_1 (
number) – The trigger value (0 to 1)
-
triggerleft:
function¶ Alias for left trigger
-
rt(
self:InputGetter,
joystick?:number|love.joystick.Joystick
):number¶ Gets the right trigger value
- Parameters:
joystick? (
number|love.joystick.Joystick) – Optional specific joystick to query- Returns:
_1 (
number) – The trigger value (0 to 1)
-
triggerright:
function¶ Alias for right trigger
-
trigger(
self:InputGetter,
joystick?:number|love.joystick.Joystick
): (left:number, right:number)¶ Gets both trigger values
- Parameters:
joystick? (
number|love.joystick.Joystick) – Optional specific joystick to query- Returns:
left (
number) – Left trigger value (0 to 1)right (
number) – Right trigger value (0 to 1)
-
_parent: {_joystickId:
-
class ControlState¶
-
pressed:
boolean¶ Whether the control was just pressed.
-
down:
boolean¶ Whether the control is held down.
-
released:
boolean¶ Whether the control was just released.
-
pressed:
-
class Controls:
Object¶ A configured set of controls.
-
get:
InputGetter¶ Getters for other inputs.
-
[
string]:ControlState¶ The state of a named control.
-
__new(self:
Controls, config:ControlsOptions)¶ - Parameters:
config (
ControlsOptions) – Configuration options.
-
setControls(self:
Controls, controls:table)¶ Sets the control configuration for this input instance
Key: string - The name of the control (e.g., “jump”, “move_left”)
Value: string|table|function - The trigger definition: - string: Single trigger (e.g., “key:space”) - table: Multiple triggers (e.g., {“key:space”, “button:a”}) - function: Custom function returning (pressed, x, y)
- Parameters:
controls (
table) – A table mapping control names to trigger definitions
-
update(self:
Controls)¶ Updates all controls for this instance. This should be called once per frame, before referencing the controls.
-
setMode(self:
Controls, mode: "both" | "joystick" | "keyboard")¶ Sets the input mode.
- Parameters:
mode ("both" | "joystick" | "keyboard") – The input mode.
-
getMode(self:
Controls): (InputMode:string)¶ Gets the current input mode.
- Returns:
InputMode (
string) – The current input mode.
-
setAutoSwitch(self:
Controls, state:boolean)¶ Sets whether to automatically switch between input modes.
- Parameters:
state (
boolean) – True to enable automatic switching.
-
getAutoSwitch(self:
Controls):boolean¶ Gets the current auto-switch setting.
- Returns:
_1 (
boolean) – True if auto-switching is enabled.
-
setJoystick(
self:Controls,
joystick:number|love.joystick.Joystick
)¶ Sets the joystick for this input instance.
- Parameters:
joystick (
number|love.joystick.Joystick) – Either a joystick ID or a LÖVE Joystick object.
-
getJoystick(self:
Controls):love.joystick.Joystick?¶ Gets the LÖVE Joystick object for this instance.
- Returns:
_1? (
love.joystick.Joystick) – The Joystick object, or nil if not found.
-
setTransform(self:
Controls, transform:love.math.Transform)¶ Sets a transform matrix for mouse coordinate conversion.
- Parameters:
transform (
love.math.Transform) – A LÖVE Transform object for coordinate conversion.
-
getTransform(self:
Controls): (transform:love.math.Transform|nil)¶ Gets the current transform matrix.
- Returns:
transform (
love.math.Transform|nil) – The current transform or nil.
-
vibrate(
self:Controls,
left:number,
right:number,
duration?:number
)¶ Vibrates the gamepad associated with this instance.
- Parameters:
left (
number) – Left motor strength (0-1).right (
number) – Right motor strength (0-1).duration? (
number) – Duration in seconds (optional).
Other members:
Inherited from
Object:_serializationBlacklist,adopt(),assertType(),className,deepcopy(),deserialize(),extend(),instanceOf(),is(),isInstance(),mixin(),prettyprint(),serializationBlacklist,serialize()-
get:
-
class ControlsOptions¶
-
controls:
table<string,string|function|string[]>¶
-
pairs:
table<string,string[]>?¶
-
mode: ("both" | "joystick" | "keyboard")?¶
-
autoSwitch:
boolean?¶
-
transform:
love.math.Transform?¶ Object containing a coordinate system transformation.
The love.graphics module has several functions and function variants which accept Transform objects.
[Open in Browser](https://love2d.org/wiki/Transform)
-
joystick: (
number|love.joystick.Joystick)?¶ Represents a physical joystick.
[Open in Browser](https://love2d.org/wiki/Joystick)
-
controls: