Skip to content
Download

Input

Inside an object, use these functions directly, with no prefix.

An action is a name tied to keys and gamepad buttons, created in Project settings. See Keyboard and gamepad with actions.

Function What it does Example
bool held(std::string_view action) const The action is held, on the keyboard or on the gamepad. if (held("atirar")) ...
bool pressed(std::string_view action) const The action was pressed on this step. True once per tap. if (pressed("pular")) vspeed = -4;
bool released(std::string_view action) const The action was released on this step. if (released("pular")) ...
float axis(std::string_view negative, std::string_view positive) const From -1 to 1: the positive action minus the negative one. The analog stick has a dead zone of 0.25. hspeed = axis("esquerda", "direita") * 2;

An action with the wrong name shows up once as an error in the Output.

Function What it does Example
bool held(Key key) const The key is held down. if (held(Key::Left)) x -= 2;
bool pressed(Key key) const The key was pressed on this step. True once per tap. if (pressed(Key::Space)) vspeed = -6;
bool released(Key key) const The key was released on this step. if (released(Key::Space)) charge = 0;
Function What it does Example
float mouseX() const X of the mouse in the world (takes the camera into account). angleTo(mouseX(), mouseY())
float mouseY() const Y of the mouse in the world.
bool mouseHeld(MouseButton button) const The button is held down. if (mouseHeld(MouseButton::Left)) ...
bool mousePressed(MouseButton button) const The button was pressed on this step. if (mousePressed(MouseButton::Right)) ...
bool mouseReleased(MouseButton button) const The button was released on this step.
float Input::mouseWheel() How much the mouse wheel turned on this step: positive up, negative down, 0 still. zoom += Input::mouseWheel();

Buttons: MouseButton::Left, MouseButton::Middle, MouseButton::Right.

For menus and buttons drawn in onRenderGui, which don’t move with the camera, use Input::mouseGuiX() and Input::mouseGuiY(): the position of the mouse on the screen.

Group Values
Letters Key::A … Key::Z
Numbers Key::Num0 … Key::Num9
Arrows Key::Left, Key::Right, Key::Up, Key::Down
Special Key::Space, Key::Enter, Key::Escape, Key::Tab, Key::Backspace
Modifiers Key::LShift, Key::RShift, Key::LCtrl, Key::RCtrl
Function keys Key::F1 … Key::F12

The gamepad is used through actions: in the project settings, tie a button to an action. The first connected gamepad is used.

Group Names
Buttons Pad:A, Pad:B, Pad:X, Pad:Y, Pad:Start, Pad:Back, Pad:LB, Pad:RB
D-pad Pad:Up, Pad:Down, Pad:Left, Pad:Right
Left stick Pad:LeftX-, Pad:LeftX+, Pad:LeftY-, Pad:LeftY+