Skip to main content

Mouse and keyboard info

Query the state of the mouse and keyboard.

Summary

Functions

Name
glm::vec2mouse() const
Returns the current mouse position.
glm::vec2mouse_delta() const
Returns the movement of the mouse since the last update().
boolmouse_is_in_window() const
Returns true iff the window is focused and the coordinates returned by mouse() correspond to a position inside the window.
boolmouse_button_is_pressed(Button button) const
Returns true iff the given mouse button is currently pressed.
boolctrl() const
Returns true iff the CTRL key is pressed (or CMD on Mac)
boolshift() const
Returns true iff the SHIFT key is pressed.
boolalt() const
Returns true iff the ALT key is pressed.
boolkey_is_pressed(int key) const
Returns true iff the given key is currently pressed.

Functions

mouse()

glm::vec2 mouse() const;

Returns the current mouse position.

mouse_delta()

glm::vec2 mouse_delta() const;

Returns the movement of the mouse since the last update().

mouse_is_in_window()

bool mouse_is_in_window() const;

Returns true iff the window is focused and the coordinates returned by mouse() correspond to a position inside the window.

mouse_button_is_pressed()

bool mouse_button_is_pressed(Button button) const;

Returns true iff the given mouse button is currently pressed.

ctrl()

bool ctrl() const;

Returns true iff the CTRL key is pressed (or CMD on Mac)

shift()

bool shift() const;

Returns true iff the SHIFT key is pressed.

alt()

bool alt() const;

Returns true iff the ALT key is pressed.

key_is_pressed()

bool key_is_pressed(int key) const;

Returns true iff the given key is currently pressed.

key should be a GLFW_KEY value. See https://www.glfw.org/docs/3.3/keys.html for the complete list. e.g. ctx.key_is_pressed(GLFW_KEY_Q) /!\ Please note that these are physical keys that don't depend on the current layout. This means that GLFW_KEY_Q will refer to the first key on your keyboard, no matter if you are using QWERTY or AZERTY.


Updated on 2024 October 24