Lua · Variables · Core
input
Keyboard and mouse state, read once a frame.
Keys use Windows virtual-key codes: 0x41 is A, 0x70 is F1, 0x20 is Space. See the key code table on Values and types. A key that the user picked in a ui.keybind comes back as the same kind of code.
While the user types in a text field of the menu, key_down and key_pressed return false, so a hotkey never fires by accident.
| Function | What it does |
|---|---|
input.key_down(vk) | True while the key is held. |
input.key_pressed(vk) | True only on the frame the key went down. Use it for toggles. |
input.mouse() | The Windows cursor position in screen pixels. |
input.mouse_down([button]) | True while a mouse button is held. |
#input.key_down
input.key_down(vk)True while the key is held.
Arguments
vkintegerVirtual-key code, 1 to 255.
Returns
boolean
true while held.
Example
if input.key_down(0x10) then speed = speed * 2 end#input.key_pressed
input.key_pressed(vk)True only on the frame the key went down. Use it for toggles.
Arguments
vkintegerVirtual-key code, 1 to 255.
Returns
boolean
true on the first frame of a press.
Example
if input.key_pressed(ui.get("toggle")) then shown = not shown end#input.mouse
input.mouse()The Windows cursor position in screen pixels.
Returns
number1
x
number2
y
- In-game the cursor is locked to the centre; this is most useful while the menu is open.
#input.mouse_down
input.mouse_down([button])True while a mouse button is held.
Arguments
buttonintegeroptional1 left (default), 2 right, 3 middle.
Returns
boolean
true while held.