Keyboard and mouse.
Key names are SDL's: letters "A"-"Z", digits "0"-"9", "F2"-"F12", "Space", "Return", "Escape",
"Tab", "Backspace", "Left Shift", "Right Shift", "Left Ctrl", "Right Ctrl", "Left Alt", "Right Alt",
"Up", "Down", "Left", "Right", "Insert", "Delete", "Home", "End", "PageUp", "PageDown", "Keypad 0"-"Keypad 9",
"Keypad +", "Keypad -", "-", "=", "[", "]", ";", "'", ",", ".", "/", "\\". F1, F9 and ` belong to the
mod menu, reload and console.
Players choose their own keys for the game's actions (Options → [CONTROLS] ); by default W A S D move, Shift runs,
Space jumps, the mouse fires and holds the binoculars, R / B / M / C / Q / 1-9 do the rest. Bind your mod's keys to
something else, and show the player's own key for a game action with keys.binding: the actions are forward back
left right run jump fire zoom binoculars weapon slot1-slot9 map call resupply cameraroll trophylock trophydelete.
# keys.bind (key , fn , priority? ) → integer
Calls fn when the key goes down. The game does not see the key, unless fn returns false.
Parameter Type
keystring key name
fnfunction fn(e), the key event
priority optional integer
Returns
integer listener id (events.off)
copy keys .bind("H" , function ()
world .god(not world .god())
game .message("God mode " .. (world .god() and "on" or "off" ))
end )
# keys.down (key ) → boolean
Whether a key is held right now.
Parameter Type
keystring key name
Returns
boolean true while held
copy on ("frame" , function (e)
if keys .down("Left Shift" ) then stamina = stamina - e.dt end
end )
# keys.mouse () → number, number, boolean, boolean, boolean
Mouse position and buttons.
Returns
number x
number y
boolean left button
boolean right
boolean middle
# keys.binding (action ) → string?, string?
The player's keys for one of the game's actions.
Parameter Type
actionstring a game action: "fire", "jump", "map" ... (see above)
Returns
string? the first key / button, e.g. "Mouse Left" or "Space"
string? the second one
copy game .message("Press " .. (keys .binding("call" ) or "?" ) .. " to call" )