Api

Input API

InputManager, MouseState, key codes, and cursor control.

Include

#include <EngineExports.hpp>
#include <input/InputManager.hpp>
#include <input/KeycodeMap.hpp>
auto& input = Public::Engine::getInstance().GetInputManager();

InputManager

APIPurpose
UpdateKeyStates()Refresh keyboard state. Engine-owned in normal games.
OnWindowFocus(bool)Notify focus changes.
IsKeyDown(int/Key::Code)Held this frame.
IsKeyUp(int/Key::Code)Not held this frame.
GetKeyDown(int/Key::Code)Pressed this frame.
UpdateMouseDelta()Refresh mouse movement delta.
IsMouseButtonDown(int)Mouse button held.
IsMouseButtonUp(int)Mouse button not held.
GetMouseState()Read mouse position, delta, and buttons.
SetMousePosition(x, y)Move the cursor.
LockCursor()Hide/lock cursor for free look.
UnlockCursor()Release cursor.
HideCursor()Hide cursor without locking.
ShowCursor()Show cursor.
IsCursorLocked()Query cursor lock.
IsWindowFocused()Query focus.
Update()Full input update. Engine-owned in normal games.

MouseState

struct MouseState {
    int x = 0;
    int y = 0;
    int deltaX = 0;
    int deltaY = 0;
    bool buttons[8] = {false};
};

Key Codes

KeycodeMap.hpp defines Public::Input::Key::Code:

if (input.GetKeyDown(Public::Input::Key::Code::Space)) {
    Jump();
}

It also defines wrapper constants in Public::Input::Key:

using namespace Public::Input::Key;

if (input.IsKeyDown(W)) {
    MoveForward();
}

Available groups:

  • Letters A through Z
  • Numbers Num0 through Num9
  • Function keys F1 through F12
  • Escape, Space, Enter, Tab, Backspace
  • Shift, Ctrl, Alt, CapsLock
  • Left, Right, Up, Down
  • Insert, Delete, Home, End, PageUp, PageDown

Focus-Safe Gameplay Input

Check focus before responding to gameplay controls that should not run while the window is inactive:

if (!input.IsWindowFocused()) {
    return;
}

The sample Freecam system combines IsWindowFocused() with cursor lock to avoid accidental camera movement while interacting with other windows.