input
One frame of input: keyboard, mouse, touch screen and gamepads, plus what went down or came up this frame. A headless run answers every query neutrally.
One frame of input: keyboard, mouse, touch screen and gamepads, plus what went down or came up this frame. A headless run answers every query neutrally.
53 functions, 188 constants. Scripts reach it as input::.
Functions
Argument kinds are the script values a call passes: node is a node handle, any a table or value of any kind, fn a callback.
| function | acts on | what it does |
|---|---|---|
action_down(string) -> bool |
— | Whether the action is held down now. |
action_just_pressed(string) -> bool |
— | Whether the action went down this frame. |
action_just_released(string) -> bool |
— | Whether the action came up this frame. |
action_value(string) -> float |
— | How far the action is pushed, -1 to 1; a key answers 0 or 1, a stick or keys:KeyA,KeyD the whole range. |
actions() -> [str] |
— | Every action [input.actions] declares, so a rebinding screen can list them. |
bind(string, [str]) |
— | Rebind the action to a list of bindings, spelled as [input.actions] spells them, replacing what it had and saving to the user data directory. |
bindings(string) -> [str] |
— | What the action is bound to now, whether from the project or from the player's own rebinding. |
composing() -> string |
— | The text an input method is still composing, for a field to show under its caret; empty once it commits into typed, and always empty without an input method. |
dropped_files() -> [str] |
— | The absolute paths of files dropped onto the window this frame, in drop order; desktop only. A script hears a drop with events::listen(this.node, "files_dropped"), as on_files_dropped(paths). |
feed_action(string, float) |
— | Put a value into an action for one frame without a binding, the way a touch_button does; the furthest from rest wins where something else feeds the same action. Takes effect on the next tick, since actions derive at the top of one. |
feed_gamepad(int, input::PadFeed) |
— | Report a pad as if a backend had, from next frame. A pad fed anything connects; connected: false unplugs it. |
feed_key(string, bool) |
— | Press or release a KEY_* key as if the window had reported it: next frame's edge, and the state until the opposite feed. |
feed_mouse(float, float) |
— | Move the cursor to a window-pixel position as if the window had reported it, from next frame; the delta accumulates for that frame. |
feed_mouse_button(int, bool) |
— | Press or release a MOUSE_BUTTON_* button as if the window had reported it, from next frame. |
feed_scroll(float, float) |
— | Turn the wheel as if the window had reported it, from next frame; adds to that frame's scroll_delta. |
feed_touch(int, float, float, string) |
— | Put a finger on the screen as if the window had reported it: phase is start, move, end or cancel, and the position is in the same pixels as mouse_position. |
gamepad_acceleration(int) -> Vec3 |
— | The pad's acceleration in g, gravity included, so a pad at rest reads 1 on one axis. Read from PlayStation pads on desktop; zero for a pad with no accelerometer. |
gamepad_axis(int, string) -> float |
— | How far the pad's GAMEPAD_AXIS_* stick or trigger is pushed: a stick -1 to 1 with up and right positive, a trigger 0 to 1, after [input] gamepad_deadzone; zero at rest and for an absent pad. |
gamepad_can_rumble(int) -> bool |
— | Whether the pad has motors to rumble; false for a pad that is not connected. |
gamepad_down(int, string) -> bool |
— | Whether the pad's GAMEPAD_BUTTON_* button is held down: pressed past [input] gamepad_press, and not yet back under gamepad_release. |
gamepad_gyro(int) -> Vec3 |
— | How fast the pad is turning, in radians per second about each axis. Read from PlayStation pads on desktop; zero for a pad with no gyroscope. |
gamepad_info(int) -> input::GamepadInfo? |
— | Who the pad is; nil for an absent pad. |
gamepad_just_pressed(int, string) -> bool |
— | Whether the pad's GAMEPAD_BUTTON_* button went down this frame; a press and a release between two frames are both seen. |
gamepad_just_released(int, string) -> bool |
— | Whether the pad's GAMEPAD_BUTTON_* button came up this frame; true for that one frame only. |
gamepad_name(int) -> string |
— | The pad's name: its mapping's when one matched, else the platform's. Empty when no pad has that id. |
gamepad_power(int) -> input::GamepadPower |
— | The pad's power. Read whenever the pad sends anything. |
gamepad_pressure(int, string) -> float |
— | How far the pad's GAMEPAD_BUTTON_* button is pressed, 0 to 1, before any deadzone: a digital button reads 0 or 1, a trigger or a pressure-sensitive button anything between. |
gamepad_repeated(int, string) -> bool |
— | True the frame the pad's GAMEPAD_BUTTON_* button goes down, then every [input] gamepad_repeat_interval_seconds once it has been held for gamepad_repeat_delay_seconds: for stepping through a menu. |
gamepad_rumble(int, input::RumbleOptions?) -> bool |
— | Rumble the pad. Options: strong and weak, the two motors at 0..1; duration in seconds; delay before it starts; pulse and gap to beat on and off; attack, attack_level, fade and fade_level to shape each pulse; position with min_distance, max_distance, falloff (inverse, linear or exponential) and rolloff to weaken it with distance from gamepad_set_listener. Returns whether the pad can rumble; a second rumble replaces the first. |
gamepad_set_listener(int, Vec3) |
— | Where the pad's player is, for a rumble given a position; until set, a placed rumble plays at full strength. |
gamepad_stop_rumble(int) |
— | Silence the pad now, without the on_gamepad_rumble_finished a rumble's natural end sends. |
gamepad_touches(int) -> [input::Touch] |
— | Every finger on the pad's touchpad, oldest first, with x and y running 0 to 1 across the surface. Read from PlayStation pads on desktop; empty for a pad with no touchpad. |
gamepads() -> [int] |
— | The ids of every connected pad: player slots from 0. A pad takes the lowest free slot last held by the same model, else the lowest free slot, and keeps it while connected. |
key_down(string) -> bool |
— | Whether the KEY_* key is held down right now, however many frames it has been down. KEY_SHIFT, KEY_CONTROL, KEY_ALT and KEY_META answer for either side. |
key_just_pressed(string) -> bool |
— | Whether the KEY_* key went down this frame; true for that one frame only. |
key_just_released(string) -> bool |
— | Whether the KEY_* key came up this frame; true for that one frame only. |
keyboard_height() -> float |
— | How much of the window the on-screen keyboard covers, in pixels from the bottom: what a form moves up by. Zero with no keyboard up, and always zero on a desktop. |
long_press() -> Vec2? |
— | Where a finger has been held still past long_press_seconds. Reported once per finger, on the frame the hold passes; nil otherwise. |
mouse_delta() -> Vec2 |
— | How far the cursor moved this frame, in pixels; movement, not a position. |
mouse_down(int) -> bool |
— | Whether the MOUSE_BUTTON_* button is held down right now, however many frames it has been down. |
mouse_just_pressed(int) -> bool |
— | Whether the MOUSE_BUTTON_* button went down this frame; true for that one frame only. |
mouse_just_released(int) -> bool |
— | Whether the MOUSE_BUTTON_* button came up this frame; true for that one frame only. |
mouse_position() -> Vec2 |
— | The cursor's position in window pixels, with (0, 0) at the top-left corner. A script hears it move with events::listen(this.node, "pointer_moved"), as on_pointer_moved([x, y]), and a button go down or up anywhere, the UI included, as pointer_pressed and pointer_released with { button, x, y }; the wheel turn as pointer_scrolled with [x, y], and two fingers as pointer_gestured with { scale, x, y, pan_x, pan_y }. |
pan() -> input::Pan |
— | Two or more fingers moving together as { x, y }, the average movement since last frame in the same pixels as mouse_position. Zero with fewer than two down. |
pinch() -> input::Pinch |
— | Two fingers moving apart or together as { scale, x, y }: scale above 1 is apart, measured against last frame, and x/y are the point between them. Empty with fewer than two fingers down. |
reset_bindings() |
— | Drop every saved rebinding and go back to what the project declared. |
scroll_delta() -> Vec2 |
— | How far the wheel turned this frame, as an (x, y) pair; zero when it did not turn. |
swipe() -> input::Swipe? |
— | A finger that travelled far enough before it lifted. Reported on the frame it lifted and never again; nil otherwise. |
touches() -> [input::Touch] |
— | Every finger on the screen, oldest first, in the same pixels as mouse_position. |
touches_just_ended() -> [int] |
— | The ids of the fingers that lifted or were cancelled this frame. |
touches_just_started() -> [int] |
— | The ids of the fingers that touched down this frame. |
typed() -> string |
— | The characters typed this frame, in order: what a text field appends, where key_just_pressed says which key went down. |
vibrate(float) |
— | Buzz the device for that many seconds: a phone's motor, or a page's navigator.vibrate. Nothing on a desktop, and never recorded, like rumble. |
Constants
| name | value |
|---|---|
GAMEPAD_AXIS_LEFT_TRIGGER |
"left_trigger" |
GAMEPAD_AXIS_LEFT_X |
"left_x" |
GAMEPAD_AXIS_LEFT_Y |
"left_y" |
GAMEPAD_AXIS_RIGHT_TRIGGER |
"right_trigger" |
GAMEPAD_AXIS_RIGHT_X |
"right_x" |
GAMEPAD_AXIS_RIGHT_Y |
"right_y" |
GAMEPAD_BUTTON_BACK |
"back" |
GAMEPAD_BUTTON_C |
"c" |
GAMEPAD_BUTTON_DPAD_DOWN |
"dpad_down" |
GAMEPAD_BUTTON_DPAD_LEFT |
"dpad_left" |
GAMEPAD_BUTTON_DPAD_RIGHT |
"dpad_right" |
GAMEPAD_BUTTON_DPAD_UP |
"dpad_up" |
GAMEPAD_BUTTON_EAST |
"east" |
GAMEPAD_BUTTON_GUIDE |
"guide" |
GAMEPAD_BUTTON_LEFT_SHOULDER |
"left_shoulder" |
GAMEPAD_BUTTON_LEFT_STICK |
"left_stick" |
GAMEPAD_BUTTON_LEFT_TRIGGER |
"left_trigger" |
GAMEPAD_BUTTON_NORTH |
"north" |
GAMEPAD_BUTTON_RIGHT_SHOULDER |
"right_shoulder" |
GAMEPAD_BUTTON_RIGHT_STICK |
"right_stick" |
GAMEPAD_BUTTON_RIGHT_TRIGGER |
"right_trigger" |
GAMEPAD_BUTTON_SOUTH |
"south" |
GAMEPAD_BUTTON_START |
"start" |
GAMEPAD_BUTTON_WEST |
"west" |
GAMEPAD_BUTTON_Z |
"z" |
GAMEPAD_FALLOFF_EXPONENTIAL |
"exponential" |
GAMEPAD_FALLOFF_INVERSE |
"inverse" |
GAMEPAD_FALLOFF_LINEAR |
"linear" |
GAMEPAD_MAPPING_DRIVER |
"driver" |
GAMEPAD_MAPPING_SDL |
"sdl" |
GAMEPAD_POWER_CHARGED |
"charged" |
GAMEPAD_POWER_CHARGING |
"charging" |
GAMEPAD_POWER_NO_BATTERY |
"no_battery" |
GAMEPAD_POWER_ON_BATTERY |
"on_battery" |
GAMEPAD_POWER_UNKNOWN |
"unknown" |
KEY_0 |
"Digit0" |
KEY_1 |
"Digit1" |
KEY_2 |
"Digit2" |
KEY_3 |
"Digit3" |
KEY_4 |
"Digit4" |
KEY_5 |
"Digit5" |
KEY_6 |
"Digit6" |
KEY_7 |
"Digit7" |
KEY_8 |
"Digit8" |
KEY_9 |
"Digit9" |
KEY_A |
"KeyA" |
KEY_ALT |
"Alt" |
KEY_APOSTROPHE |
"Quote" |
KEY_AUDIO_VOLUME_DOWN |
"AudioVolumeDown" |
KEY_AUDIO_VOLUME_MUTE |
"AudioVolumeMute" |
KEY_AUDIO_VOLUME_UP |
"AudioVolumeUp" |
KEY_B |
"KeyB" |
KEY_BACKQUOTE |
"Backquote" |
KEY_BACKSLASH |
"Backslash" |
KEY_BACKSPACE |
"Backspace" |
KEY_BROWSER_BACK |
"BrowserBack" |
KEY_BROWSER_FORWARD |
"BrowserForward" |
KEY_BROWSER_HOME |
"BrowserHome" |
KEY_BROWSER_REFRESH |
"BrowserRefresh" |
KEY_BROWSER_SEARCH |
"BrowserSearch" |
KEY_C |
"KeyC" |
KEY_CAPS_LOCK |
"CapsLock" |
KEY_COMMA |
"Comma" |
KEY_CONTEXT_MENU |
"ContextMenu" |
KEY_CONTROL |
"Control" |
KEY_CONVERT |
"Convert" |
KEY_COPY |
"Copy" |
KEY_CUT |
"Cut" |
KEY_D |
"KeyD" |
KEY_DELETE |
"Delete" |
KEY_DOWN |
"ArrowDown" |
KEY_E |
"KeyE" |
KEY_END |
"End" |
KEY_ENTER |
"Enter" |
KEY_EQUAL |
"Equal" |
KEY_ESCAPE |
"Escape" |
KEY_F |
"KeyF" |
KEY_F1 |
"F1" |
KEY_F10 |
"F10" |
KEY_F11 |
"F11" |
KEY_F12 |
"F12" |
KEY_F13 |
"F13" |
KEY_F14 |
"F14" |
KEY_F15 |
"F15" |
KEY_F16 |
"F16" |
KEY_F17 |
"F17" |
KEY_F18 |
"F18" |
KEY_F19 |
"F19" |
KEY_F2 |
"F2" |
KEY_F20 |
"F20" |
KEY_F21 |
"F21" |
KEY_F22 |
"F22" |
KEY_F23 |
"F23" |
KEY_F24 |
"F24" |
KEY_F3 |
"F3" |
KEY_F4 |
"F4" |
KEY_F5 |
"F5" |
KEY_F6 |
"F6" |
KEY_F7 |
"F7" |
KEY_F8 |
"F8" |
KEY_F9 |
"F9" |
KEY_G |
"KeyG" |
KEY_H |
"KeyH" |
KEY_HOME |
"Home" |
KEY_I |
"KeyI" |
KEY_INSERT |
"Insert" |
KEY_INTERNATIONAL_BACKSLASH |
"IntlBackslash" |
KEY_INTERNATIONAL_RO |
"IntlRo" |
KEY_INTERNATIONAL_YEN |
"IntlYen" |
KEY_J |
"KeyJ" |
KEY_K |
"KeyK" |
KEY_KANA_MODE |
"KanaMode" |
KEY_L |
"KeyL" |
KEY_LAUNCH_MAIL |
"LaunchMail" |
KEY_LEFT |
"ArrowLeft" |
KEY_LEFT_ALT |
"AltLeft" |
KEY_LEFT_BRACKET |
"BracketLeft" |
KEY_LEFT_CONTROL |
"ControlLeft" |
KEY_LEFT_META |
"MetaLeft" |
KEY_LEFT_SHIFT |
"ShiftLeft" |
KEY_M |
"KeyM" |
KEY_MEDIA_PLAY_PAUSE |
"MediaPlayPause" |
KEY_MEDIA_SELECT |
"MediaSelect" |
KEY_MEDIA_STOP |
"MediaStop" |
KEY_MEDIA_TRACK_NEXT |
"MediaTrackNext" |
KEY_MEDIA_TRACK_PREVIOUS |
"MediaTrackPrevious" |
KEY_META |
"Meta" |
KEY_MINUS |
"Minus" |
KEY_N |
"KeyN" |
KEY_NON_CONVERT |
"NonConvert" |
KEY_NUMPAD_0 |
"Numpad0" |
KEY_NUMPAD_1 |
"Numpad1" |
KEY_NUMPAD_2 |
"Numpad2" |
KEY_NUMPAD_3 |
"Numpad3" |
KEY_NUMPAD_4 |
"Numpad4" |
KEY_NUMPAD_5 |
"Numpad5" |
KEY_NUMPAD_6 |
"Numpad6" |
KEY_NUMPAD_7 |
"Numpad7" |
KEY_NUMPAD_8 |
"Numpad8" |
KEY_NUMPAD_9 |
"Numpad9" |
KEY_NUMPAD_ADD |
"NumpadAdd" |
KEY_NUMPAD_COMMA |
"NumpadComma" |
KEY_NUMPAD_DIVIDE |
"NumpadDivide" |
KEY_NUMPAD_ENTER |
"NumpadEnter" |
KEY_NUMPAD_EQUAL |
"NumpadEqual" |
KEY_NUMPAD_MULTIPLY |
"NumpadMultiply" |
KEY_NUMPAD_PERIOD |
"NumpadDecimal" |
KEY_NUMPAD_SUBTRACT |
"NumpadSubtract" |
KEY_NUM_LOCK |
"NumLock" |
KEY_O |
"KeyO" |
KEY_P |
"KeyP" |
KEY_PAGE_DOWN |
"PageDown" |
KEY_PAGE_UP |
"PageUp" |
KEY_PASTE |
"Paste" |
KEY_PAUSE |
"Pause" |
KEY_PERIOD |
"Period" |
KEY_POWER |
"Power" |
KEY_PRINT_SCREEN |
"PrintScreen" |
KEY_Q |
"KeyQ" |
KEY_R |
"KeyR" |
KEY_RIGHT |
"ArrowRight" |
KEY_RIGHT_ALT |
"AltRight" |
KEY_RIGHT_BRACKET |
"BracketRight" |
KEY_RIGHT_CONTROL |
"ControlRight" |
KEY_RIGHT_META |
"MetaRight" |
KEY_RIGHT_SHIFT |
"ShiftRight" |
KEY_S |
"KeyS" |
KEY_SCROLL_LOCK |
"ScrollLock" |
KEY_SEMICOLON |
"Semicolon" |
KEY_SHIFT |
"Shift" |
KEY_SLASH |
"Slash" |
KEY_SLEEP |
"Sleep" |
KEY_SPACE |
"Space" |
KEY_T |
"KeyT" |
KEY_TAB |
"Tab" |
KEY_U |
"KeyU" |
KEY_UP |
"ArrowUp" |
KEY_V |
"KeyV" |
KEY_W |
"KeyW" |
KEY_WAKE_UP |
"WakeUp" |
KEY_X |
"KeyX" |
KEY_Y |
"KeyY" |
KEY_Z |
"KeyZ" |
MOUSE_BUTTON_BACK |
3 |
MOUSE_BUTTON_FORWARD |
4 |
MOUSE_BUTTON_LEFT |
0 |
MOUSE_BUTTON_MIDDLE |
2 |
MOUSE_BUTTON_RIGHT |
1 |