On this page
  1. stick
  2. action
  3. Reading actions
  4. pressed
  5. just_pressed
  6. just_released
  7. pressed, just_pressed, just_released
  8. axis_value
  9. Directions
  10. axis
  11. vector
  12. axis, vector
  13. The pointer
  14. pointer_screen
  15. pointer, pointer_delta
  16. pointer_down, pointer_pressed, pointer_released
  17. Escape hatches
  18. deadzone, set_deadzone
  19. consumed_pointer, consumed_keyboard

rmp::input

namespace #include <rmp/input.h>

rmp::input — named actions, and who gets to hear them.

Two things raylib deliberately does not decide for you, and a game needs both on its first day.

rmp::input::action("jump", KEY_SPACE, KEY_W, GAMEPAD_BUTTON_RIGHT_FACE_DOWN);
if (rmp::input::just_pressed("jump")) player.jump();

A name and as many bindings as you like. The TYPE of each one says which device it belongs to — raylib's KeyboardKey, MouseButton and GamepadButton are different enums in C++ — so the dispatch happens at compile time and passing anything else is a compile error that names the argument.

And moving in eight directions, with keyboard, d-pad and stick at once, with no configuration at all:

player.velocity = rmp::input::vector() * speed;

THE PART THAT IS NOT OBVIOUS is who gets to hear an action. A finger that presses a UI button must not also fire the gun underneath it, and that has to be true without anyone writing an if. So a query BY NAME is routed:

rmp::input::just_pressed("fire")   // silent while the UI wants the pointer
rmp::input::pressed(KEY_W)         // raw, exactly IsKeyDown, never routed

The argument type says which of the two you asked for, and you can see it at the call site without going to look anything up.

stick

constexpr detail::Binding stick(::GamepadAxis axis, int sign)

Half of an analogue stick, as a binding. The one place you write something that is not a plain raylib constant:

rmp::input::action("left", KEY_A, rmp::input::stick(GAMEPAD_AXIS_LEFT_X, -1));

sign is -1 or +1 and says which way counts. Anything else is clamped to those two, because a stick has two halves and there is no third thing to mean.

action

template <class First, class... Rest> void action(std::string_view name, First first, Rest... rest)

Define an action. At least one binding — an action with none is a mistake the compiler can catch, so it does.

REGISTERING THE SAME NAME AGAIN REPLACES IT. It does not add to it. That is what makes calling these from a scene's _ready() safe when the player enters that scene twenty times, which is where they naturally get written.

Reading actions

pressed

bool pressed(std::string_view name)

Held down

just_pressed

bool just_pressed(std::string_view name)

The frame it goes down

just_released

bool just_released(std::string_view name)

The frame it comes up

pressed, just_pressed, just_released

bool pressed(::KeyboardKey key)
bool pressed(::MouseButton button)
bool pressed(::GamepadButton button)
bool just_pressed(::KeyboardKey key)
bool just_pressed(::MouseButton button)
bool just_pressed(::GamepadButton button)
bool just_released(::KeyboardKey key)
bool just_released(::MouseButton button)
bool just_released(::GamepadButton button)

BY DEVICE these are raw: exactly IsKeyDown and friends, never routed, for when you want to know regardless of who else is listening.

axis_value

float axis_value(::GamepadAxis which)

The raw position of an analogue axis, -1..+1, with the dead zone applied. A stick that reports past its end reads its end, and one that reports something that is not a number reads 0.

Directions

axis

float axis(std::string_view negative, std::string_view positive)

-1, 0 or +1 from two actions, or the analogue value when a stick is what is moving them. negative and positive pressed at once gives 0, which is what a player mashing both keys expects.

vector

Vector2 vector(std::string_view left, std::string_view right, std::string_view up, std::string_view down)

A direction from four actions, NORMALISED — so going diagonally is not 41 % faster than going straight. That is the single most common bug in 2D movement code and it costs one line here instead of being everybody's to remember.

+Y is DOWN, matching raylib's screen coordinates and rmp::Object::position, so "up" gives a negative Y and nothing has to be flipped on the way out.

axis, vector

float axis()
Vector2 vector()

The movement every game starts with, already bound: axis() is axis("move_left", "move_right"), and vector() is vector("move_left", "move_right", "move_up", "move_down"). A game that never calls action() moves with the keyboard, a d-pad and a stick at once, because these come defined out of the box:

move_left   KEY_A, KEY_LEFT        d-pad left    left stick -X
move_right  KEY_D, KEY_RIGHT       d-pad right   left stick +X
move_up     KEY_W, KEY_UP          d-pad up      left stick -Y
move_down   KEY_S, KEY_DOWN        d-pad down    left stick +Y
ui_accept   KEY_ENTER, KEY_SPACE   bottom face button
ui_cancel   KEY_ESCAPE             right face button

They are ordinary actions: action("move_left", ...) replaces one, and axis() and vector() read what it was given from then on.

The pointer

pointer_screen

Vector2 pointer_screen()

In pixels, top-left origin

pointer, pointer_delta

Vector2 pointer()
Vector2 pointer_delta()

In WORLD units, through the current scene's camera — what you compare an object's position with — and so through [window] stretch as well: on a letterboxed window, a pointer on a bar is outside the world. Same as pointer_screen() while the camera is where it starts AND the window is the design size — under NONE too, a bigger window puts the design's middle in its middle — and in a game with no scenes (RMP_ENTRY_POINT), which has no camera to go through.

pointer_delta: How far it moved since the last frame, in pixels

pointer_down, pointer_pressed, pointer_released

bool pointer_down()
bool pointer_pressed()
bool pointer_released()

The left mouse button, which a touch presses too: held, the frame it goes down, the frame it comes up. Raw like pressed(MOUSE_BUTTON_LEFT), never routed.

Escape hatches

deadzone, set_deadzone

float deadzone()
void set_deadzone(float value)

The dead zone below which a stick reads as zero. From [input] deadzone in raylib_multiplatform.toml; set it here to change it at runtime, clamped to 0..0.95 so a slider cannot switch the sticks off. NaN changes nothing, and is said once.

consumed_pointer, consumed_keyboard

bool consumed_pointer()
bool consumed_keyboard()

Is anything above the caller holding the input? Useful for drawing a different cursor, or for code that wants the reason rather than the answer.