Skip to content

Input

Raw key and mouse state, cursor grabbing, vanilla keybind overrides and camera perspective.

input

Raw window state, before any keybind mapping.

Function Does
input.key_down(code) true while a key is held. GLFW code, 32 is space
input.mouse_down(btn) true while a button is held: 0 left, 1 right, 2 middle
input.mouse_pos() Cursor x, y in render_2d canvas pixels
input.mouse_locked() true while the cursor is grabbed
input.lock(), input.unlock() Grabs the cursor (hidden and locked), or releases it
if input.key_down(340) then     -- left shift
    local x, y = input.mouse_pos()
    print(x, y)
end

For a bind the player can rebind in the panel, declare a hotkey setting instead.

options

Vanilla keybinds and the camera view.

Function Does
options.key(name) true while that binding is pressed
options.set_key(name, down) Holds or releases the binding
options.perspective() "first_person", "third_person_back", "third_person_front"
options.set_perspective(p) Forces the view; unknown names are ignored
options.sensitivity() Mouse sensitivity slider, 0..1, default 0.5

name is one of "forward", "backward", "left", "right", "jump", "sneak", "sprint", "attack", "use".

set_key drives the vanilla binding, and a key you hold stays down until a physical key event releases it, so call it every tick to keep holding.

module:event("tick", function()
    if options.perspective() == "first_person" then
        options.set_perspective("third_person_back")
    end
    options.set_key("forward", true)
end)
Navigation

Type to search…

↑↓ navigate↵ selectEsc close