input
Keyboard and mouse state; keys use Windows virtual-key codes.
Functions
input.is_key_down
input.is_key_down(key) -> boolean| Name | Type | Description |
|---|---|---|
| key | integer | string | Code or name, like 0x20 or "SPACE". |
Live hardware state of a key.
Returns true while physically held
- An unknown key name raises an error.
- False while the game window is not focused.
input.is_key_pressed
input.is_key_pressed(key) -> boolean| Name | Type | Description |
|---|---|---|
| key | integer | string | Code or name. |
Edge-triggered: true once when the key goes down.
Returns true once per press
- Tracked per script: two scripts polling one key both see the press.
- A tap that starts and ends between two calls is missed.
- No presses while the game window is not focused.
input.cursor_position
input.cursor_position() -> x, yOverlay mouse cursor position.
Returns screen pixels
Returns 0, 0 before the overlay initialises.
input.mouse_delta
input.mouse_delta() -> dx, dyOverlay cursor movement this frame.
Returns pixels moved since last frame
Returns 0, 0 before the overlay initialises.
input.scroll
input.scroll() -> numberVertical wheel movement this frame.
Returns positive is up, about 1 per notch
input.is_mouse_down
input.is_mouse_down([button = 0]) -> boolean| Name | Type | Description |
|---|---|---|
| buttonoptional | integer | 0 left, 1 right, 2 middle, 3/4 side. Default 0. |
Mouse button state from the overlay.
Returns true while held
Buttons outside 0 to 4 return false.
input.mouse_clicked
input.mouse_clicked([button = 0]) -> boolean| Name | Type | Description |
|---|---|---|
| buttonoptional | integer | 0 left, 1 right, 2 middle, 3/4 side. Default 0. |
Per-frame mouse click edge.
Returns true only on the press frame
Every caller in a frame gets the same answer.
input.set_cursor_free
input.set_cursor_free(on)| Name | Type | Description |
|---|---|---|
| on | boolean | false lets go at once. |
Free mouse cursor in game while the menu is closed.
- The view stops turning and clicks do not fire while it is on.
- Expires after about 150 ms, so call it every frame.
input.set_text_capture
input.set_text_capture(on)| Name | Type | Description |
|---|---|---|
| on | boolean | false lets go at once. |
Takes the keyboard for a text field; the game gets no keys.
- Works only while input.set_cursor_free is on.
- Expires after about 150 ms, so call it every frame.
input.read_text
input.read_text() -> stringCharacters typed since the last call, UTF-8.
- Control keys come as characters: "\b", "\r", "\27", "\t".
- Holds 128 characters between calls; the rest is dropped.
input.keys
Key names to codes: A to Z, 0 to 9, F1 to F12, MOUSE1 to MOUSE5, SPACE, SHIFT, CTRL, ALT and more.
Every key argument takes a name or a code, any case: input.is_key_down("f").
input.key_name
input.key_name(key) -> string | nil| Name | Type |
|---|---|
| key | integer |
Name of a key code.
input.key_code
input.key_code(key) -> integer| Name | Type |
|---|---|
| key | string |
Code of a key name; 0 when unknown.
input.is_cursor_visible
input.is_cursor_visible() -> booleanThe menu or the game's own UI (console, buy menu, pause menu) shows a cursor.
input.is_focused
input.is_focused() -> booleanTrue while the game window is in the foreground.