class Input

Inherits: Module<Input>

Primary module used for dealing with input.

Allows you to receieve and query raw or OS input for mouse/keyboard/gamepad.

Public

Constructors

Input

Input()

Methods

~Input

~Input() noexcept

GetAxisValue

float GetAxisValue(u32 type, u32 deviceIndex = 0) const

Returns value of the specified input axis.

Normally in range [-1.0, 1.0] but can be outside the range for devices with unbound axes (for example mouse).

type
Type of axis to query. Usually a type from InputAxis but can be a custom value.
deviceIndex
Index of the device in case more than one is hooked up (0 - primary).

IsButtonHeld

bool IsButtonHeld(ButtonCode keyCode, u32 deviceIndex = 0) const

Query if the provided button is currently being held (this frame or previous frames).

keyCode
Code of the button to query.
deviceIndex
Device to query the button on (0 - primary).

IsButtonUp

bool IsButtonUp(ButtonCode keyCode, u32 deviceIndex = 0) const

Query if the provided button is currently being released (only true for one frame).

keyCode
Code of the button to query.
deviceIndex
Device to query the button on (0 - primary).

IsButtonDown

bool IsButtonDown(ButtonCode keyCode, u32 deviceIndex = 0) const

Query if the provided button is currently being pressed (only true for one frame).

keyCode
Code of the button to query.
deviceIndex
Device to query the button on (0 - primary).

GetPointerPosition

Vector2I GetPointerPosition() const

Returns position of the pointer (for example mouse cursor) relative to the screen.

GetPointerDelta

Vector2I GetPointerDelta() const

Returns difference between pointer position between current and last frame.

IsPointerButtonHeld

bool IsPointerButtonHeld(PointerEventButton pointerButton) const

Query if the provided pointer button is currently being held (this frame or previous frames).

pointerButton
Code of the button to query.

IsPointerButtonUp

bool IsPointerButtonUp(PointerEventButton pointerButton) const

Query if the provided pointer button is currently being released (only true for one frame).

pointerButton
Code of the button to query.

IsPointerButtonDown

bool IsPointerButtonDown(PointerEventButton pointerButton) const

Query if the provided pointer button is currently being pressed (only true for one frame).

pointerButton
Code of the button to query.

IsPointerDoubleClicked

bool IsPointerDoubleClicked() const

Query has the left pointer button has been double-clicked this frame.

SetMouseSmoothing

void SetMouseSmoothing(bool enabled)

Enables or disables mouse smoothing.

Smoothing makes the changes to mouse axes more gradual.

GetDeviceCount

u32 GetDeviceCount(InputDevice device) const

Returns the number of detected devices of the specified type.

GetDeviceName

String GetDeviceName(InputDevice type, u32 deviceIndex)

Returns the name of a specific input device.

Returns empty string if the device doesn't exist.

staticInstance

static T &Instance()

Returns a reference to the module instance.

Module has to have been started up first otherwise an exception will be thrown.

staticInstancePtr

static T *InstancePtr()

Returns a pointer to the module instance.

Module has to have been started up first otherwise an exception will be thrown.

staticShutDown

static void ShutDown()

Shuts down this module and frees any resources it is using.

staticIsStarted

static bool IsStarted()

Query if the module has been started.

Fields

OnButtonDown

Event<void (const ButtonEvent &)> OnButtonDown

Triggered whenever a button is first pressed.

OnButtonUp

Event<void (const ButtonEvent &)> OnButtonUp

Triggered whenever a button is first released.

OnCharInput

Event<void (const TextInputEvent &)> OnCharInput

Triggered whenever user inputs a text character.

OnPointerMoved

Event<void (const PointerEvent &)> OnPointerMoved

Triggers when some pointing device (mouse cursor, touch) moves.

OnPointerPressed

Event<void (const PointerEvent &)> OnPointerPressed

Triggers when some pointing device (mouse cursor, touch) button is pressed.

OnPointerReleased

Event<void (const PointerEvent &)> OnPointerReleased

Triggers when some pointing device (mouse cursor, touch) button is released.

OnPointerDoubleClick

Event<void (const PointerEvent &)> OnPointerDoubleClick

Triggers when some pointing device (mouse cursor, touch) button is double clicked.

OnInputCommand

Event<void (InputCommandType)> OnInputCommand

Triggers on special input commands.

Internal

Methods

UpdateInternal

void UpdateInternal()

Called every frame.

Detects button state changes and prepares callback events to trigger via a call to TriggerCallbacksInternal().

TriggerCallbacksInternal

void TriggerCallbacksInternal()

Triggers any queued input event callbacks.

GetPrivateDataInternal

InputPrivateData *GetPrivateDataInternal() const

Returns internal, platform specific privata data.

GetWindowHandle

u64 GetWindowHandle() const

Returns a handle to the window that is currently receiving input.

NotifyMouseMovedInternal

void NotifyMouseMovedInternal(i32 relativeX, i32 relativeY, i32 relativeZ)

Called by Mouse when mouse movement is detected.

NotifyAxisMovedInternal

void NotifyAxisMovedInternal(u32 gamepadIndex, u32 axisIndex, i32 value)

Called by any of the raw input devices when analog axis movement is detected.

NotifyButtonPressedInternal

void NotifyButtonPressedInternal(u32 deviceIndex, ButtonCode code, u64 timestamp)

Called by any of the raw input devices when a button is pressed.

NotifyButtonReleasedInternal

void NotifyButtonReleasedInternal(u32 deviceIndex, ButtonCode code, u64 timestamp)

Called by any of the raw input devices when a button is released.

Protected

Methods

~Module<T>

virtual ~Module<T>() = default

OnStartUp

virtual void OnStartUp()

Override if you want your module to be notified once it has been constructed and started.

OnShutDown

virtual void OnShutDown()

Override if you want your module to be notified just before it is deleted.

staticInstanceInternal

static T *&InstanceInternal()

Returns a singleton instance of this module.

staticIsDestroyed

static bool &IsDestroyed()

Checks has the Module been shut down.

staticIsStartedUp

static bool &IsStartedUp()

Checks has the Module been started up.

Private

Methods

InitRawInput

void InitRawInput()

Performs platform specific raw input system initialization.

CleanUpRawInput

void CleanUpRawInput()

Performs platform specific raw input system cleanup.

SmoothMouse

float SmoothMouse(float value, u32 axisIndex)

Smooths the input mouse axis value.

Smoothing makes the changes to the axis more gradual depending on previous values.

value
Value to smooth.
axisIndex
Index of the mouse axis to smooth, 0 - horizontal, 1 - vertical.

Returns: Smoothed value.

ButtonDown

void ButtonDown(u32 deviceIndex, ButtonCode code, u64 timestamp)

Triggered by input handler when a button is pressed.

ButtonUp

void ButtonUp(u32 deviceIndex, ButtonCode code, u64 timestamp)

Triggered by input handler when a button is released.

AxisMoved

void AxisMoved(u32 deviceIndex, float value, u32 axis)

Triggered by input handler when a mouse/joystick axis is moved.

CharInput

void CharInput(u32 character)

Called from the message loop to notify user has entered a character.

CursorMoved

void CursorMoved(const Vector2I &cursorPosition, const OSPointerButtonStates &buttonStates)

Called from the message loop to notify user has moved the cursor.

CursorPressed

void CursorPressed(const Vector2I &cursorPosition, OSMouseButton button, const OSPointerButtonStates &buttonStates)

Called from the message loop to notify user has pressed a mouse button.

CursorReleased

void CursorReleased(const Vector2I &cursorPosition, OSMouseButton button, const OSPointerButtonStates &buttonStates)

Called from the message loop to notify user has released a mouse button.

CursorDoubleClick

void CursorDoubleClick(const Vector2I &cursorPosition, const OSPointerButtonStates &buttonStates)

Called from the message loop to notify user has double-clicked a mouse button.

InputCommandEntered

void InputCommandEntered(InputCommandType commandType)

Called from the message loop to notify user has entered an input command.

MouseWheelScrolled

void MouseWheelScrolled(float scrollPos)

Called from the message loop to notify user has scrolled the mouse wheel.

InputWindowChanged

void InputWindowChanged(RenderWindow &win)

Called when window in focus changes, as reported by the OS.

InputFocusLost

void InputFocusLost()

Called when the current window loses input focus.

This might be followed by inputWindowChanged() if the focus just switched to another of this application's windows.

Fields

mMutex

Mutex mMutex

mDevices

Vector<DeviceData> mDevices

mLastPointerPosition

Vector2I mLastPointerPosition

mPointerDelta

Vector2I mPointerDelta

mPointerButtonStates

ButtonState[3] mPointerButtonStates

mPointerDoubleClicked

bool mPointerDoubleClicked

mLastPositionSet

bool mLastPositionSet

mPointerPosition

Vector2I mPointerPosition

mMouseScroll

float mMouseScroll

mPointerState

OSPointerButtonStates mPointerState

mQueuedEvents

Vector<QueuedEvent>[2] mQueuedEvents

mTextInputEvents

Vector<TextInputEvent>[2] mTextInputEvents

mCommandEvents

Vector<InputCommandType>[2] mCommandEvents

mPointerDoubleClickEvents

Vector<PointerEvent>[2] mPointerDoubleClickEvents

mPointerReleasedEvents

Vector<PointerEvent>[2] mPointerReleasedEvents

mPointerPressedEvents

Vector<PointerEvent>[2] mPointerPressedEvents

mButtonDownEvents

Vector<ButtonEvent>[2] mButtonDownEvents

mButtonUpEvents

Vector<ButtonEvent>[2] mButtonUpEvents

mCharInputConn

HEvent mCharInputConn

mCursorMovedConn

HEvent mCursorMovedConn

mCursorPressedConn

HEvent mCursorPressedConn

mCursorReleasedConn

HEvent mCursorReleasedConn

mCursorDoubleClickConn

HEvent mCursorDoubleClickConn

mInputCommandConn

HEvent mInputCommandConn

mMouseWheelScrolledConn

HEvent mMouseWheelScrolledConn

mMouseSmoothingEnabled

bool mMouseSmoothingEnabled

mWindowHandle

u64 mWindowHandle

mMouse

Mouse * mMouse

mKeyboard

Keyboard * mKeyboard

mGamepads

Vector<Gamepad *> mGamepads

mTotalMouseSamplingTime

float[2] mTotalMouseSamplingTime

mTotalMouseSampleCount

u32[2] mTotalMouseSampleCount

mMouseZeroTime

float[2] mMouseZeroTime

mMouseSampleAccumulator

i32[2] mMouseSampleAccumulator

mMouseSmoothedAxis

float[2] mMouseSmoothedAxis

mLastMouseUpdateFrame

u64 mLastMouseUpdateFrame

mTimestampClockOffset

u64 mTimestampClockOffset

mPlatformData

InputPrivateData * mPlatformData