# rmp::input

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

Source: https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html

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.

```cpp
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:

```cpp
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:

```cpp
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)

function [include/rmp/input.h:84](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L84-L87)

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

```cpp
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)

function [include/rmp/input.h:95](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L95-L98)

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)

function [include/rmp/input.h:126](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L126)

Held down

### `just_pressed`

bool just_pressed(std::string_view name)

function [include/rmp/input.h:127](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L127)

The frame it goes down

### `just_released`

bool just_released(std::string_view name)

function [include/rmp/input.h:128](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L128)

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)

function [include/rmp/input.h:132](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L132)

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)

function [include/rmp/input.h:145](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L145)

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)

function [include/rmp/input.h:154](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L154)

-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)

function [include/rmp/input.h:162](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L162-L163)

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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#position), so "up" gives a negative Y and nothing has to be flipped on the way out.

### `axis`, `vector`

float axis()

Vector2 vector()

function [include/rmp/input.h:180](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L180)

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:

```cpp
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()

function [include/rmp/input.h:190](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L190)

In pixels, top-left origin

### `pointer`, `pointer_delta`

Vector2 pointer()

Vector2 pointer_delta()

function [include/rmp/input.h:198](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L198)

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()

function [include/rmp/input.h:202](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L202)

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)

function [include/rmp/input.h:218](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L218)

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()

function [include/rmp/input.h:223](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L223)

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.
