InputManager
- Module
- Input
- Header
#include "Input/InputManager.h"- Namespace
Mowo
Properties
| Type | Name | Description |
|---|---|---|
static constexpr int | MaxGamepads | Default 4. |
Constructors
| Signature | Name | Description |
|---|---|---|
InputManager() | InputManager | |
~InputManager() | ~InputManager |
Public functions
| Returns | Name | Description |
|---|---|---|
void | Initialize | |
void | Shutdown | |
void | Update | Frame update - call at start of each frame |
bool | IsKeyDown | |
bool | IsKeyPressed | |
bool | IsKeyReleased | |
bool | IsKeyDown | |
bool | IsKeyPressed | |
bool | IsKeyReleased | |
bool | IsShiftDown | |
bool | IsControlDown | |
bool | IsAltDown | |
bool | IsMouseButtonDown | |
bool | IsMouseButtonPressed | |
bool | IsMouseButtonReleased | |
float | GetMouseX | |
float | GetMouseY | |
void | GetMousePosition | |
float | GetMouseDeltaX | |
float | GetMouseDeltaY | |
void | GetMouseDelta | |
float | GetScrollDelta | |
bool | IsGamepadConnected | |
bool | IsGamepadButtonDown | |
bool | IsGamepadButtonPressed | |
bool | IsGamepadButtonReleased | |
float | GetGamepadAxis | |
void | OnGamepadButtonDown | The platform layer addresses pads by PHYSICAL index — the slot SDL's enumeration handed the device on connect. |
void | OnGamepadButtonUp | |
void | OnGamepadAxis | |
void | OnGamepadConnected | |
void | OnGamepadConnected | deviceId is a stable identity for the hardware (the SDL GUID string); a pad that carries one lands in the slot the user last assigned it. |
void | OnGamepadDisconnected | |
bool | AssignGamepadSlot | Explicit player-slot assignment. |
int | GetGamepadPhysicalIndex | Physical index feeding a logical slot, -1 when nothing is mapped there. |
const std::string& | GetGamepadDeviceId | |
void | SetGamepadSlotPreferencesPath | Per-user slot preferences: <Project>/Saved/Config/InputUser.mdfb when a project is open, else the per-user product dir. |
const std::string& | GetGamepadSlotPreferencesPath | |
bool | LoadGamepadSlotPreferences | |
bool | SaveGamepadSlotPreferences | |
void | SetGamepadNativeHandle | Window hands the opaque SDL_Gamepad* through here so GamepadInput can drive rumble. |
bool | RumbleGamepad | Rumble — forwards to GamepadInput. |
bool | RumbleGamepadTriggers | |
void | StopGamepadRumble | |
void | OnGamepadSensor | Window feeds SDL_EVENT_GAMEPAD_SENSOR_UPDATE here (same device index as OnGamepadAxis); tests inject synthetic samples through it. |
bool | GetGamepadGyro | Gyro (rad/s) / accelerometer (m/s^2). |
bool | GetGamepadAccel | |
bool | SetGamepadLed | Light-bar colour 0..1; false when the pad has no RGB LED. |
TouchInput& | GetTouch | |
const TouchInput& | GetTouch | |
void | OnFingerDown | Window calls these from SDL_EVENT_FINGER_* after converting normalised 0..1 coords to window pixels. |
void | OnFingerMotion | |
void | OnFingerUp | |
void | OnFingerCanceled | |
KeyboardInput& | GetKeyboard | |
const KeyboardInput& | GetKeyboard | |
MouseInput& | GetMouse | |
const MouseInput& | GetMouse | |
GamepadInput& | GetGamepad | |
const GamepadInput& | GetGamepad | |
void | OnKeyDown | Event handlers - called by Window. |
void | OnKeyUp | |
void | OnMouseButtonDown | |
void | OnMouseButtonUp | |
void | OnMouseMove | |
void | OnMouseScroll | |
void | OnMouseHorizontalScroll | |
void | OnCharInput | |
void | SetMouseDelta | |
void | InjectKeyDown | Synthetic input for tests, automation and accessibility tooling. |
void | InjectKeyUp | |
void | InjectMouseButtonDown | |
void | InjectMouseButtonUp | |
void | InjectMouseMove | |
void | InjectMouseDelta | |
void | InjectMouseScroll | |
void | InjectGamepadButtonDown | |
void | InjectGamepadButtonUp | |
void | InjectGamepadAxis | |
void | InjectFingerDown | |
void | InjectFingerUp | |
void | ResetDeviceStateOnFocusLoss | Focus loss: the OS never delivers key-ups for keys held across an Alt-Tab, so every held key/button gets a synthetic release through the normal Up sinks (releases are never suppressed and triggers see a real Completed edge), and axes/deltas zero. |
uint32_t | GetFocusLossSerial | Bumped by every focus-loss reset. |
const std::vector<uint32_t>& | GetCharBuffer | |
void | SetInputMode | Gameplay sets the input mode when a menu opens/closes. |
EInputMode | GetInputMode | |
void | SetUIConsumedCurrentEvent | "consumed" means the UI ACTED on this one event — a widget handled it, a modal or menu owned it, or the focused widget swallowed it. |
bool | IsGameInputSuppressed | |
EInputDevice | GetLastInputDevice | Updated on every device event so a HUD can query which button-prompt family to show. |
bool | LastInputWasGamepad | |
void | SetGamepadKind | Physical index (Window calls it on connect); the family lands on the logical slot the pad resolves to. |
EInputDevice | GetGamepadKind | |
void | SetCursorLockRequested | Cursor lock request (for FPS-style mouse capture) Game code calls these, engine applies them each frame. |
bool | IsCursorLockRequested | |
bool | IsCursorLockSuppressedByEscape | Engine-internal: sync pass uses this to decide whether to actually engage. |
void | NotifyUserEscapedLock | ESC handler calls this — locks out re-engagement until the user clicks in the window or game code does an explicit lock=false → lock=true cycle. |
void | NotifyUserClicked | Mouse click clears the escape — the next sync re-engages if the game still wants the lock. |
void | SetCursorVisible | Cursor visibility (separate from lock) |
bool | IsCursorVisibleRequested | |
void | SetCursorConfineMode | |
ECursorConfine | GetCursorConfineMode | The mode the sync pass should honour: the i.CursorConfine override when it is set, else what game code asked for. |
ECursorConfine | GetRequestedCursorConfineMode | |
bool | ShouldConfineCursor | What the engine's sync pass should apply this frame. |
bool | StartRecording | |
bool | StopRecording | |
bool | IsRecording | |
bool | StartPlayback | |
void | StopPlayback | |
bool | IsPlaying | |
bool | IsPlaybackFinished | |
void | EndInputFrame | Engine hook — called once per frame after Update() + window event pump + SetMouseDelta so the recorder's frame marker bundles every event from *this* frame. |
Function details
InputManager
InputManager()~InputManager
~InputManager()Initialize
void Initialize()Shutdown
void Shutdown()Update
void Update()Frame update - call at start of each frame
IsKeyDown
bool IsKeyDown(KeyCode key) constIsKeyPressed
bool IsKeyPressed(KeyCode key) constIsKeyReleased
bool IsKeyReleased(KeyCode key) constIsKeyDown
bool IsKeyDown(int vkCode) constIsKeyPressed
bool IsKeyPressed(int vkCode) constIsKeyReleased
bool IsKeyReleased(int vkCode) constIsShiftDown
bool IsShiftDown() constIsControlDown
bool IsControlDown() constIsAltDown
bool IsAltDown() constIsMouseButtonDown
bool IsMouseButtonDown(MouseButton button) constIsMouseButtonPressed
bool IsMouseButtonPressed(MouseButton button) constIsMouseButtonReleased
bool IsMouseButtonReleased(MouseButton button) constGetMouseX
float GetMouseX() constGetMouseY
float GetMouseY() constGetMousePosition
void GetMousePosition(float& x, float& y) constGetMouseDeltaX
float GetMouseDeltaX() constGetMouseDeltaY
float GetMouseDeltaY() constGetMouseDelta
void GetMouseDelta(float& dx, float& dy) constGetScrollDelta
float GetScrollDelta() constIsGamepadConnected
bool IsGamepadConnected(int index = 0) constIsGamepadButtonDown
bool IsGamepadButtonDown(GamepadButton button, int index = 0) constIsGamepadButtonPressed
bool IsGamepadButtonPressed(GamepadButton button, int index = 0) constIsGamepadButtonReleased
bool IsGamepadButtonReleased(GamepadButton button, int index = 0) constGetGamepadAxis
float GetGamepadAxis(GamepadAxis axis, int index = 0) constOnGamepadButtonDown
void OnGamepadButtonDown(int index, GamepadButton button)The platform layer addresses pads by PHYSICAL index — the slot SDL's enumeration handed the device on connect. Every sink below translates that to the LOGICAL player slot the queries, bindings (gamepad_index) and the recorder speak; see AssignGamepadSlot.
OnGamepadButtonUp
void OnGamepadButtonUp(int index, GamepadButton button)OnGamepadAxis
void OnGamepadAxis(int index, GamepadAxis axis, float value)OnGamepadConnected
void OnGamepadConnected(int index)OnGamepadConnected
void OnGamepadConnected(int index, const std::string& deviceId)deviceId is a stable identity for the hardware (the SDL GUID string); a pad that carries one lands in the slot the user last assigned it.
OnGamepadDisconnected
void OnGamepadDisconnected(int index)AssignGamepadSlot
bool AssignGamepadSlot(int currentSlot, int newSlot)Explicit player-slot assignment. Without it the first pad plugged in is always player 1, so a couch session cannot put the host's pad on slot 2 without re-plugging in the right order. Swaps the pad in currentSlot with whatever occupies newSlot (state, native handle and family move with it) and remembers the choice per device id in the user file, so the next connect of that hardware lands in the same slot.
GetGamepadPhysicalIndex
int GetGamepadPhysicalIndex(int slot) constPhysical index feeding a logical slot, -1 when nothing is mapped there.
GetGamepadDeviceId
const std::string& GetGamepadDeviceId(int slot) constSetGamepadSlotPreferencesPath
void SetGamepadSlotPreferencesPath(const std::string& path)Per-user slot preferences: <Project>/Saved/Config/InputUser.mdfb when a project is open, else the per-user product dir. Resolved lazily on the first connect so a manager created before the project loads still writes next to that project.
GetGamepadSlotPreferencesPath
const std::string& GetGamepadSlotPreferencesPath() constLoadGamepadSlotPreferences
bool LoadGamepadSlotPreferences()SaveGamepadSlotPreferences
bool SaveGamepadSlotPreferences() constSetGamepadNativeHandle
void SetGamepadNativeHandle(int index, void* sdlGamepad)Window hands the opaque SDL_Gamepad* through here so GamepadInput can drive rumble. nullptr clears (disconnect path).
RumbleGamepad
bool RumbleGamepad(int index, float lowFreq, float highFreq, uint32_t durationMs)Rumble — forwards to GamepadInput. lowFreq/highFreq in 0..1, duration in milliseconds (0 stops). Out-of-range index or unsupported pad → false.
RumbleGamepadTriggers
bool RumbleGamepadTriggers(int index, float leftTrigger, float rightTrigger, uint32_t durationMs)StopGamepadRumble
void StopGamepadRumble(int index)OnGamepadSensor
void OnGamepadSensor(int index, bool gyro, float x, float y, float z)Window feeds SDL_EVENT_GAMEPAD_SENSOR_UPDATE here (same device index as OnGamepadAxis); tests inject synthetic samples through it.
GetGamepadGyro
bool GetGamepadGyro(int index, GamepadInput::SensorSample& out)Gyro (rad/s) / accelerometer (m/s^2). The first call starts the pad's sensor stream; returns false until a pad that has the sensor delivers it. Aiming reads the gyro, the scanner/flashlight sway reads the accelerometer.
GetGamepadAccel
bool GetGamepadAccel(int index, GamepadInput::SensorSample& out)SetGamepadLed
bool SetGamepadLed(int index, float r, float g, float b)Light-bar colour 0..1; false when the pad has no RGB LED. Scanner and health state use it. i.RumbleScale does not apply.
GetTouch
TouchInput& GetTouch()GetTouch
const TouchInput& GetTouch() constOnFingerDown
void OnFingerDown(uint64_t fingerId, float x, float y, float pressure)Window calls these from SDL_EVENT_FINGER_* after converting normalised 0..1 coords to window pixels.
OnFingerMotion
void OnFingerMotion(uint64_t fingerId, float x, float y, float dx, float dy, float pressure)OnFingerUp
void OnFingerUp(uint64_t fingerId, float x, float y, float pressure)OnFingerCanceled
void OnFingerCanceled(uint64_t fingerId)GetKeyboard
KeyboardInput& GetKeyboard()GetKeyboard
const KeyboardInput& GetKeyboard() constGetMouse
MouseInput& GetMouse()GetMouse
const MouseInput& GetMouse() constGetGamepad
GamepadInput& GetGamepad(int index)GetGamepad
const GamepadInput& GetGamepad(int index) constOnKeyDown
void OnKeyDown(int vkCode)Event handlers - called by Window. When a recording is active the On* call forwards to the recorder before touching the subsystem. When a playback is active the On* call is *suppressed* — real OS events get dropped on the floor for the duration of the replay so they can't pollute the recorded state. The playback re-enters these same sinks via an internal "injecting" flag that bypasses both gates so injected events still reach the subsystems and never re-record.
OnKeyUp
void OnKeyUp(int vkCode)OnMouseButtonDown
void OnMouseButtonDown(MouseButton button)OnMouseButtonUp
void OnMouseButtonUp(MouseButton button)OnMouseMove
void OnMouseMove(float x, float y)OnMouseScroll
void OnMouseScroll(float delta)OnMouseHorizontalScroll
void OnMouseHorizontalScroll(float delta)OnCharInput
void OnCharInput(uint32_t codepoint)SetMouseDelta
void SetMouseDelta(float dx, float dy)InjectKeyDown
void InjectKeyDown(int vkCode)Synthetic input for tests, automation and accessibility tooling. An injected event lands in the device subsystems exactly like a replayed one: it bypasses the playback suppression gate and the UI-consumed gate, and is never recorded (a recording should capture the user, not the harness driving them).
InjectKeyUp
void InjectKeyUp(int vkCode)InjectMouseButtonDown
void InjectMouseButtonDown(MouseButton button)InjectMouseButtonUp
void InjectMouseButtonUp(MouseButton button)InjectMouseMove
void InjectMouseMove(float x, float y)InjectMouseDelta
void InjectMouseDelta(float dx, float dy)InjectMouseScroll
void InjectMouseScroll(float delta)InjectGamepadButtonDown
void InjectGamepadButtonDown(int index, GamepadButton button)InjectGamepadButtonUp
void InjectGamepadButtonUp(int index, GamepadButton button)InjectGamepadAxis
void InjectGamepadAxis(int index, GamepadAxis axis, float value)InjectFingerDown
void InjectFingerDown(uint64_t fingerId, float x, float y, float pressure)InjectFingerUp
void InjectFingerUp(uint64_t fingerId, float x, float y, float pressure)ResetDeviceStateOnFocusLoss
void ResetDeviceStateOnFocusLoss()Focus loss: the OS never delivers key-ups for keys held across an Alt-Tab, so every held key/button gets a synthetic release through the normal Up sinks (releases are never suppressed and triggers see a real Completed edge), and axes/deltas zero. Without this the character walks into a wall forever after a focus switch mid-WASD.
GetFocusLossSerial
uint32_t GetFocusLossSerial() constBumped by every focus-loss reset. Anything that latches key state OUTSIDE the device bitsets (the editor fly camera keeps its own WASD flags) polls this once a frame and drops its latches when it moves — the OS never sends those key-ups either.
GetCharBuffer
const std::vector<uint32_t>& GetCharBuffer() constSetInputMode
void SetInputMode(EInputMode mode)Gameplay sets the input mode when a menu opens/closes. The platform event pump sets the per-event "UI consumed this" flag from the UI layer's return value BEFORE forwarding the event to the On* sinks below; those sinks then drop the event for gameplay when IsGameInputSuppressed() is true. Device tracking (below) still updates regardless — a suppressed gamepad press still means the player is on a gamepad.
GetInputMode
EInputMode GetInputMode() constSetUIConsumedCurrentEvent
void SetUIConsumedCurrentEvent(bool consumed)"consumed" means the UI ACTED on this one event — a widget handled it, a modal or menu owned it, or the focused widget swallowed it. It must never mean "something is focused": a HUD button that keeps focus after a click would then suppress every key the game reads for as long as it holds it. The resulting policy, per event class: key down / character suppressed only when the UI took THAT key, so a focused text box eats typing and nothing else key up / button up never suppressed (the Up sinks ignore the gate), or a key held into a focus change stays down mouse button down suppressed only when a widget handled the press; a click nobody took reaches the game mouse motion / wheel suppressed only while a widget is dragging or scrolling with it, so mouse look survives a cursor resting over the HUD gamepad the UI layer never sees pad events, so only EInputMode::UIOnly withholds them
IsGameInputSuppressed
bool IsGameInputSuppressed() constGetLastInputDevice
EInputDevice GetLastInputDevice() constUpdated on every device event so a HUD can query which button-prompt family to show. The gamepad *family* (Xbox / PlayStation / Nintendo / generic) is resolved by the platform layer on connect and pushed via SetGamepadKind; per-slot until then it is GamepadGeneric.
LastInputWasGamepad
bool LastInputWasGamepad() constSetGamepadKind
void SetGamepadKind(int index, EInputDevice kind)Physical index (Window calls it on connect); the family lands on the logical slot the pad resolves to.
GetGamepadKind
EInputDevice GetGamepadKind(int index) constSetCursorLockRequested
void SetCursorLockRequested(bool lock)Cursor lock request (for FPS-style mouse capture) Game code calls these, engine applies them each frame. The "user escaped" sticky flag (set by NotifyUserEscapedLock when ESC fires) overrides game intent — even if a script calls this every Update, the engine won't re-engage the lock until the user *clicks* in the window (Unity-style "ESC frees, click re-locks"). Setting lock=false from game code clears the escape too, so a hand-off between scripts works naturally.
IsCursorLockRequested
bool IsCursorLockRequested() constIsCursorLockSuppressedByEscape
bool IsCursorLockSuppressedByEscape() constEngine-internal: sync pass uses this to decide whether to actually engage. While true, ignore m_wantCursorLock.
NotifyUserEscapedLock
void NotifyUserEscapedLock()ESC handler calls this — locks out re-engagement until the user clicks in the window or game code does an explicit lock=false → lock=true cycle.
NotifyUserClicked
void NotifyUserClicked()Mouse click clears the escape — the next sync re-engages if the game still wants the lock. Window calls this on any button-down. A click the UI took is not the click this means. In a non-modal pause screen — the default — the first press on a menu button re-engaged the lock, the cursor went back to relative mode, and the menu could not be clicked again.
SetCursorVisible
void SetCursorVisible(bool visible)Cursor visibility (separate from lock)
IsCursorVisibleRequested
bool IsCursorVisibleRequested() constSetCursorConfineMode
void SetCursorConfineMode(ECursorConfine mode)GetCursorConfineMode
ECursorConfine GetCursorConfineMode() constThe mode the sync pass should honour: the i.CursorConfine override when it is set, else what game code asked for.
GetRequestedCursorConfineMode
ECursorConfine GetRequestedCursorConfineMode() constShouldConfineCursor
static bool ShouldConfineCursor(ECursorConfine mode, bool windowFocused, bool cursorLocked)What the engine's sync pass should apply this frame. Focus is a hard gate in every mode: confining a cursor the user has alt-tabbed away from is how an application stops being closable.
StartRecording
bool StartRecording(const std::string& outputPath)StopRecording
bool StopRecording()IsRecording
bool IsRecording() constStartPlayback
bool StartPlayback(const std::string& inputPath)StopPlayback
void StopPlayback()IsPlaying
bool IsPlaying() constIsPlaybackFinished
bool IsPlaybackFinished() constEndInputFrame
void EndInputFrame()Engine hook — called once per frame after Update() + window event pump + SetMouseDelta so the recorder's frame marker bundles every event from *this* frame. No-op when not recording.