QuasarEngine
Cross-platform 3D engine and editor
Loading...
Searching...
No Matches
Quasar::Input Namespace Reference

Functions that read the current state of the keyboard, the mouse and the gamepads, as an alternative to events. More...

Functions

bool IsKeyPressed (Key key)
 Returns true if the key is held down.
bool IsMouseButtonPressed (MouseButton button)
 Returns true if the mouse button is held down.
glm::vec2 GetMousePosition ()
 Returns the position of the cursor, in screen coordinates, from the top-left corner of the drawing area.
bool IsGamepadConnected (GamepadId gamepad)
 Returns true if a gamepad is connected with this id. See Gamepads.
bool IsGamepadButtonPressed (GamepadId gamepad, GamepadButton button)
 Returns true if the button of the gamepad is held down. False when the gamepad is not connected.
float GetGamepadAxis (GamepadId gamepad, GamepadAxis axis)
 Returns the value of an axis of the gamepad, after the dead zones.

Detailed Description

Functions that read the current state of the keyboard, the mouse and the gamepads, as an alternative to events.

Use them for continuous actions, like moving a camera while a key is held down: if (Input::IsKeyPressed(Key::W)) { MoveForward(timestep); }. Use events for single actions, like a click or a shortcut, so that no press is missed between two frames.

The functions read the main window and the gamepads of the application, so an Application must exist. The state is the one known at the end of the last frame, when the messages of the operating system and the gamepads are read.

Function Documentation

◆ IsKeyPressed()

bool Quasar::Input::IsKeyPressed ( Key key)

Returns true if the key is held down.

Key codes are physical keys: Key::W is the key at the position of W on QWERTY, which is Z on AZERTY.

◆ GetMousePosition()

glm::vec2 Quasar::Input::GetMousePosition ( )

Returns the position of the cursor, in screen coordinates, from the top-left corner of the drawing area.

Like MouseMovedEvent, the position is not in pixels on a scaled display.

◆ GetGamepadAxis()

float Quasar::Input::GetGamepadAxis ( GamepadId gamepad,
GamepadAxis axis )

Returns the value of an axis of the gamepad, after the dead zones.

0 when the gamepad is not connected.

Stick axes go from -1 to 1, -1 being left or up. Triggers go from 0, at rest, to 1, fully pressed. See GamepadSettings for the dead zones.