Input

High-level input handling and management.

Overview

Typical use cases:

  • Querying the state of keyboard keys

  • Querying mouse position and button states

Header

<RaeptorCogs/IO/Input.hpp>

Metadata

Author

Estorc

Version

v1.0

Copyright

Copyright (c) 2025 Estorc MIT License.

Enums

Enumerations

Enum

Description

RaeptorCogs::Key

Key enumeration for keyboard input.

RaeptorCogs::Singletons::MouseButton

Mouse button enumeration.

enum class RaeptorCogs::Key : uint32_t

Key enumeration for keyboard input.

Represents various keys on the keyboard, mapped to GLFW key codes.

Values:

enumerator UNKNOWN
enumerator SPACE
enumerator APOSTROPHE
enumerator PLUS
enumerator MINUS
enumerator COMMA
enumerator PERIOD
enumerator SLASH
enumerator KEY_0
enumerator KEY_1
enumerator KEY_2
enumerator KEY_3
enumerator KEY_4
enumerator KEY_5
enumerator KEY_6
enumerator KEY_7
enumerator KEY_8
enumerator KEY_9
enumerator SEMICOLON
enumerator EQUAL
enumerator A
enumerator B
enumerator C
enumerator D
enumerator E
enumerator F
enumerator G
enumerator H
enumerator I
enumerator J
enumerator K
enumerator L
enumerator M
enumerator N
enumerator O
enumerator P
enumerator Q
enumerator R
enumerator S
enumerator T
enumerator U
enumerator V
enumerator W
enumerator X
enumerator Y
enumerator Z
enumerator LEFT_BRACKET
enumerator BACKSLASH
enumerator RIGHT_BRACKET
enumerator GRAVE_ACCENT
enumerator WORLD_1
enumerator WORLD_2
enumerator ESCAPE
enumerator ENTER
enumerator TAB
enumerator BACKSPACE
enumerator INSERT
enumerator DELETE_KEY
enumerator RIGHT_ARROW
enumerator LEFT_ARROW
enumerator DOWN_ARROW
enumerator UP_ARROW
enumerator PAGE_UP
enumerator PAGE_DOWN
enumerator HOME
enumerator END
enumerator CAPS_LOCK
enumerator SCROLL_LOCK
enumerator NUM_LOCK
enumerator PRINT_SCREEN
enumerator LEFT_SHIFT
enumerator LEFT_CONTROL
enumerator LEFT_ALT
enumerator LEFT_SUPER
enumerator RIGHT_SHIFT
enumerator RIGHT_CONTROL
enumerator RIGHT_ALT
enumerator RIGHT_SUPER
enumerator MENU
enumerator KEY_COUNT
enum class RaeptorCogs::Singletons::MouseButton : uint8_t

Mouse button enumeration.

Represents various mouse buttons, mapped to GLFW button codes.

Values:

enumerator LEFT
enumerator RIGHT
enumerator MIDDLE
enumerator BUTTON_4
enumerator BUTTON_5
enumerator BUTTON_6
enumerator BUTTON_7
enumerator BUTTON_8
enumerator BUTTON_COUNT

Classes

Classes

Class

Description

RaeptorCogs::Singletons::Input

Input handling class.

RaeptorCogs::Singletons::Mouse

Mouse input handling class.

class Input

Input handling class.

Provides methods to query the state of keyboard keys.

if (RaeptorCogs::Input().isKeyPressed(RaeptorCogs::Key::SPACE)) {
    // Space key is currently pressed
}

Public Functions

bool isKeyPressed(Key key)

Check if a key is currently pressed.

if (RaeptorCogs::Input().isKeyPressed(RaeptorCogs::Key::A)) {
    // 'A' key is currently pressed
}

Parameters:

keyKey to check.

Returns:

true if the key is pressed, false otherwise.

bool isKeyReleased(Key key)

Check if a key was released.

if (RaeptorCogs::Input().isKeyReleased(RaeptorCogs::Key::ESCAPE)) {
    // Escape key was just released
}

Parameters:

keyKey to check.

Returns:

true if the key was released, false otherwise.

void update(Window &window)

Update the input states.

Is called once per frame to update key states.

Note

Updates are already handled internally; manual calls are not required.

Parameters:

window – Reference to the Window instance.

Private Functions

Input() = default

Private constructor.

~Input() = default

Private destructor.

Private Members

std::bitset<static_cast<size_t>(Key::KEY_COUNT)> keyStates

Key state bitsets.

Stores the current states of all keys.

std::bitset<static_cast<size_t>(Key::KEY_COUNT)> prevKeyStates

Previous key state bitsets.

Stores the previous states of all keys for edge detection.

friend SingletonAccessor< Input >

Friend declaration for SingletonAccessor.

Necessary for Singleton pattern implementation.

class Mouse

Mouse input handling class.

Provides methods to query the state of mouse buttons and cursor position.

if (RaeptorCogs::Mouse().isButtonPressed(RaeptorCogs::MouseButton::LEFT)) {
    // Left mouse button is currently pressed
}
double mouseX = RaeptorCogs::Mouse().getX();

Public Functions

bool isButtonPressed(int button)

Check if a mouse button is currently pressed.

if (RaeptorCogs::Mouse().isButtonPressed(RaeptorCogs::MouseButton::LEFT)) {
    // Left mouse button is currently pressed
}

Parameters:

buttonMouse button to check.

Returns:

true if the button is pressed, false otherwise.

bool isButtonReleased(int button)

Check if a mouse button was released.

if (RaeptorCogs::Mouse().isButtonReleased(RaeptorCogs::MouseButton::RIGHT)) {
    // Right mouse button was just released
}

Parameters:

buttonMouse button to check.

Returns:

true if the button was released, false otherwise.

double getScrollX() const

Get the horizontal scroll offset.

Returns:

Horizontal scroll offset.

double getScrollY() const

Get the vertical scroll offset.

Returns:

Vertical scroll offset.

glm::vec2 getScroll() const

Get the scroll offset as a vector.

Returns:

Scroll offset (x, y) as a glm::vec2.

double getX() const

Get the current X position of the mouse cursor.

Returns:

X position of the cursor.

double getY() const

Get the current Y position of the mouse cursor.

Returns:

Y position of the cursor.

glm::vec2 getPosition() const

Get the current position of the mouse cursor.

Returns:

Position of the cursor as a glm::vec2.

uint64_t getHoveredData() const

Get the hovered data identifier.

Returns:

Hovered data identifier.

void setHoveredData(uint64_t data)

Set the hovered data identifier.

Note

This is done internally by the system.

Parameters:

data – Hovered data identifier to set.

void updateScroll(double xoffset, double yoffset)

Update the scroll offsets.

Note

This is done internally by the system.

Parameters:
  • xoffset – Horizontal scroll offset.

  • yoffset – Vertical scroll offset.

void update(Window &window)

Update the mouse.

Is called once per frame to update button states and cursor position.

Note

Updates are already handled internally; manual calls are not required.

Parameters:

window – Reference to the Window instance.

Private Functions

Mouse() = default

Private constructor.

~Mouse() = default

Private destructor.

Private Members

std::bitset<static_cast<size_t>(MouseButton::BUTTON_COUNT)> buttonStates

Mouse button state bitsets.

Stores the current states of all mouse buttons.

std::bitset<static_cast<size_t>(MouseButton::BUTTON_COUNT)> prevButtonStates

Previous mouse button state bitsets.

Stores the previous states of all mouse buttons for edge detection.

glm::vec2 scroll = glm::vec2(0.0f)

Scroll offset.

Stores the accumulated scroll offsets.

glm::vec2 position = glm::vec2(0.0f)

Current mouse position.

Stores the current cursor position.

uint64_t hoveredData = 0

Hovered data identifier.

Stores an identifier for the currently hovered object.

Note

Can be used for object picking or UI interactions.

friend SingletonAccessor< Mouse >

Friend declaration for SingletonAccessor.

Necessary for Singleton pattern implementation.