InputManager class
A singleton class that manages all keyboard and mouse input.
It provides a simple interface for checking the state of keys and the mouse.
Public static functions
- static auto Get() -> InputManager&
- Returns a reference to the singleton
InputManagerinstance.
Public functions
- auto IsKeyDown(KeyCode key_code) const -> bool
- Checks if a key is currently being held down.
- auto IsKeyPressed(KeyCode key_code) const -> bool
- Checks if a key was pressed during the current frame.
- auto IsKeyReleased(KeyCode key_code) const -> bool
- Checks if a key was released during the current frame.
- auto mouse_screen_pos() const -> glm::vec2
- Retrieves the mouse position in screen coordinates.
- void UpdateState()
- Updates the key states for the current frame.
Function documentation
static InputManager& engine:: InputManager:: Get()
Returns a reference to the singleton InputManager instance.
| Returns | Reference to the InputManager. |
|---|
bool engine:: InputManager:: IsKeyPressed(KeyCode key_code) const
Checks if a key was pressed during the current frame.
| Parameters | |
|---|---|
| key_code | The KeyCode to check. |
| Returns | true if the key was pressed in this frame, false otherwise. |
This is a single-frame event.
bool engine:: InputManager:: IsKeyReleased(KeyCode key_code) const
Checks if a key was released during the current frame.
| Parameters | |
|---|---|
| key_code | The KeyCode to check. |
| Returns | true if the key was released in this frame, false otherwise. |
This is a single-frame event.
glm::vec2 engine:: InputManager:: mouse_screen_pos() const
Retrieves the mouse position in screen coordinates.
| Returns | the screen position in [-1, 1] space. |
|---|
void engine:: InputManager:: UpdateState()
Updates the key states for the current frame.
This should be called once per frame by the main application loop.