Skip to content

Input

Static methods for reading mouse, keyboard, modifier keys, and gamepad state. All methods are static.

Returns: Num — Current mouse X or Y position (in window or design coordinates depending on setup).

var x = Input.mouseX()
var y = Input.mouseY()
Gui.label("Mouse: %(x), %(y)")

Input.mouseLeft() / Input.mouseRight() / Input.mouseMiddle()

Section titled “Input.mouseLeft() / Input.mouseRight() / Input.mouseMiddle()”

Returns: Booltrue if the left, right, or middle button is currently held.

if (Input.mouseLeft()) {
// drag or hold logic
}

Input.mouseJustPressedLeft() / Input.mouseJustPressedRight()

Section titled “Input.mouseJustPressedLeft() / Input.mouseJustPressedRight()”

Returns: Booltrue if the button was just pressed this frame (edge-triggered, so only true for one frame per press).

if (Input.mouseJustPressedLeft()) {
tryStartDrag()
}

Returns: Num — Scroll delta for this frame (horizontal and vertical wheel). Zero when not scrolling.

Returns: Booltrue if the key with the given name is currently held.

Parameters:

  • name (String) — Key name (e.g. "a", "space", "escape", "Left", "Right").
if (Input.key("a")) position = position - speed * dt
if (Input.key("d")) position = position + speed * dt

Returns: Booltrue if the key was just pressed this frame.

Parameters:

  • name (String) — Key name.
if (Input.keyJustPressed("space")) {
Audio.play(_jumpSound)
}

Input.modShift() / Input.modCtrl() / Input.modAlt()

Section titled “Input.modShift() / Input.modCtrl() / Input.modAlt()”

Returns: Booltrue if the Shift, Ctrl, or Alt modifier is held.

if (Input.keyJustPressed("s") && Input.modCtrl()) saveGame()

Returns: Num — Number of connected gamepads (0-based; 0 = none, 1 = first gamepad, etc.).

Returns: Bool — Whether the given button is held on the specified gamepad.

Parameters:

  • player (Num) — Player/gamepad index (0-based).
  • button (Num or String) — Button index or name (implementation-dependent).

Returns: Num — Axis value (e.g. -1 to 1 for sticks).

Parameters:

  • player (Num) — Gamepad index (0-based).
  • axis (Num or String) — Axis index or name (e.g. left stick X/Y).