Input
Static methods for reading mouse, keyboard, modifier keys, and gamepad state. All methods are static.
Input.mouseX() / Input.mouseY()
Section titled “Input.mouseX() / Input.mouseY()”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: Bool — true 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: Bool — true if the button was just pressed this frame (edge-triggered, so only true for one frame per press).
if (Input.mouseJustPressedLeft()) { tryStartDrag()}Input.mouseWheelX() / Input.mouseWheelY()
Section titled “Input.mouseWheelX() / Input.mouseWheelY()”Returns: Num — Scroll delta for this frame (horizontal and vertical wheel). Zero when not scrolling.
Keyboard
Section titled “Keyboard”Input.key(name)
Section titled “Input.key(name)”Returns: Bool — true 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 * dtif (Input.key("d")) position = position + speed * dtInput.keyJustPressed(name)
Section titled “Input.keyJustPressed(name)”Returns: Bool — true 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: Bool — true if the Shift, Ctrl, or Alt modifier is held.
if (Input.keyJustPressed("s") && Input.modCtrl()) saveGame()Gamepad
Section titled “Gamepad”Input.gamepadCount()
Section titled “Input.gamepadCount()”Returns: Num — Number of connected gamepads (0-based; 0 = none, 1 = first gamepad, etc.).
Input.gamepadButton(player, button)
Section titled “Input.gamepadButton(player, button)”Returns: Bool — Whether the given button is held on the specified gamepad.
Parameters:
player(Num) — Player/gamepad index (0-based).button(NumorString) — Button index or name (implementation-dependent).
Input.gamepadAxis(player, axis)
Section titled “Input.gamepadAxis(player, axis)”Returns: Num — Axis value (e.g. -1 to 1 for sticks).
Parameters:
player(Num) — Gamepad index (0-based).axis(NumorString) — Axis index or name (e.g. left stick X/Y).