Class Input#
Defined in File Input.h
Nested Relationships#
Nested Types#
Class Documentation#
-
class Input#
Remark
Headless mode: This class is not available in headless mode.
Public Types
-
enum class Key#
Keyboard keys.
Values:
-
enumerator Unknown#
-
enumerator Space#
-
enumerator Apostrophe#
-
enumerator Comma#
-
enumerator Minus#
-
enumerator Period#
-
enumerator Slash#
-
enumerator Zero#
-
enumerator One#
-
enumerator Two#
-
enumerator Three#
-
enumerator Four#
-
enumerator Five#
-
enumerator Six#
-
enumerator Seven#
-
enumerator Eight#
-
enumerator Nine#
-
enumerator Semicolon#
-
enumerator Equal#
-
enumerator A#
-
enumerator B#
-
enumerator C#
-
enumerator D#
-
enumerator E#
-
enumerator F#
-
enumerator G#
-
enumerator H#
-
enumerator I#
-
enumerator J#
-
enumerator K#
-
enumerator L#
-
enumerator M#
-
enumerator N#
-
enumerator O#
-
enumerator P#
-
enumerator Q#
-
enumerator R#
-
enumerator S#
-
enumerator T#
-
enumerator U#
-
enumerator V#
-
enumerator W#
-
enumerator X#
-
enumerator Y#
-
enumerator Z#
-
enumerator Left_Bracket#
-
enumerator Backslash#
-
enumerator Right_Bracket#
-
enumerator Grave_Accent#
-
enumerator World_1#
-
enumerator World_2#
-
enumerator Escape#
-
enumerator Enter#
-
enumerator Tab#
-
enumerator Backspace#
-
enumerator Insert#
-
enumerator Delete#
-
enumerator Right#
-
enumerator Left#
-
enumerator Down#
-
enumerator Up#
-
enumerator Page_Up#
-
enumerator Page_Down#
-
enumerator Home#
-
enumerator End#
-
enumerator Caps_Lock#
-
enumerator Scroll_Lock#
-
enumerator Num_Lock#
-
enumerator Print_Screen#
-
enumerator Pause#
-
enumerator F1#
-
enumerator F2#
-
enumerator F3#
-
enumerator F4#
-
enumerator F5#
-
enumerator F6#
-
enumerator F7#
-
enumerator F8#
-
enumerator F9#
-
enumerator F10#
-
enumerator F11#
-
enumerator F12#
-
enumerator F13#
-
enumerator F14#
-
enumerator F15#
-
enumerator F16#
-
enumerator F17#
-
enumerator F18#
-
enumerator F19#
-
enumerator F20#
-
enumerator F21#
-
enumerator F22#
-
enumerator F23#
-
enumerator F24#
-
enumerator F25#
-
enumerator KP_0#
-
enumerator KP_1#
-
enumerator KP_2#
-
enumerator KP_3#
-
enumerator KP_4#
-
enumerator KP_5#
-
enumerator KP_6#
-
enumerator KP_7#
-
enumerator KP_8#
-
enumerator KP_9#
-
enumerator KP_Decimal#
-
enumerator KP_Divide#
-
enumerator KP_Multiply#
-
enumerator KP_Subtract#
-
enumerator KP_Add#
-
enumerator KP_Enter#
-
enumerator KP_Equal#
-
enumerator Left_Shift#
-
enumerator Left_Control#
-
enumerator Left_ALT#
-
enumerator Left_Super#
-
enumerator Right_Shift#
-
enumerator Right_Control#
-
enumerator Right_ALT#
-
enumerator Right_Super#
-
enumerator Menu#
-
enumerator Unknown#
-
enum class KeyState : u32#
Key state.
Values:
-
enumerator Released#
-
enumerator Pressed#
-
enumerator Repeat#
-
enumerator Released#
-
enum class MouseButton : u32#
Mouse buttons.
Values:
-
enumerator One#
-
enumerator Two#
-
enumerator Three#
-
enumerator Four#
-
enumerator Five#
-
enumerator Six#
-
enumerator Seven#
-
enumerator Eight#
-
enumerator Left#
-
enumerator Right#
-
enumerator Middle#
-
enumerator One#
-
enum class Controller : u32#
Controllers.
Values:
-
enumerator One#
-
enumerator Two#
-
enumerator Three#
-
enumerator Four#
-
enumerator Five#
-
enumerator Six#
-
enumerator Seven#
-
enumerator Eight#
-
enumerator Nine#
-
enumerator Ten#
-
enumerator Eleven#
-
enumerator Twelve#
-
enumerator Thirteen#
-
enumerator Fourteen#
-
enumerator Fifteen#
-
enumerator Sixteen#
-
enumerator One#
-
enum class ControllerAxis : u32#
Controller axes.
Values:
-
enumerator Left_X#
-
enumerator Left_Y#
-
enumerator Right_X#
-
enumerator Right_Y#
-
enumerator Left_Trigger#
-
enumerator Right_Trigger#
-
enumerator Left_X#
-
enum class ControllerButton : u32#
Controller buttons.
Values:
-
enumerator A#
-
enumerator B#
-
enumerator X#
-
enumerator Y#
-
enumerator Left_Bumper#
-
enumerator Right_Bumper#
-
enumerator Back#
-
enumerator Start#
-
enumerator Guide#
-
enumerator Left_Thumb#
-
enumerator Right_Thumb#
-
enumerator DPad_Up#
-
enumerator DPad_Right#
-
enumerator DPad_Down#
-
enumerator DPad_Left#
-
enumerator Cross#
-
enumerator Circle#
-
enumerator Square#
-
enumerator Triangle#
-
enumerator A#
-
enum class ControllerDPad : u32#
Controller DPad.
Values:
-
enumerator Centered#
-
enumerator Up#
-
enumerator Right#
-
enumerator Down#
-
enumerator Left#
-
enumerator Right_Up#
-
enumerator Right_Down#
-
enumerator Left_Up#
-
enumerator Left_Down#
-
enumerator Centered#
Public Static Functions
-
static bool IsKeyPressed(Key key)#
Check if a button on the keyboard is pressed.
- Parameters:
key – Key to check.
- Returns:
True if provided key is pressed, false otherwise.
-
static bool IsKeyPressed(Key key, const Window *window)#
Check if a button on the keyboard in the specified window is pressed.
- Parameters:
key – Key to check.
window – Window to check on.
- Returns:
True if provided key is pressed in provided window, false otherwise.
-
static bool IsMouseButtonPressed(MouseButton button)#
Check if a mouse button on the mouse is pressed.
- Parameters:
button – Mouse button to check.
- Returns:
True if provided mouse button is pressed, false otherwise.
-
static bool IsMouseButtonPressed(MouseButton button, const Window *window)#
Check if a mouse button on the mouse in the specified window is pressed.
- Parameters:
button – Mouse button to check.
window – Window to check on.
- Returns:
True if provided mouse button is pressed in provided window, false otherwise.
-
static bool IsRawMouseInputSupported()#
Retrieve whether raw mouse input is supported.
- Returns:
True if raw mouse input is supported, false otherwise.
-
static constexpr bool IsControllerConnected(Controller controller)#
Check if a specific controller is connected.
- Parameters:
controller – Controller to check
- Returns:
True if provided controller is connected, false otherwise.
-
static bool IsControllerGamepad(Controller controller)#
Check if a controller is a Gamepad (is able to map to an XBox like controller).
- Parameters:
controller – Controller to check.
- Returns:
True if controller is a Gamepad, false otherwise.
-
static Math::Vec2 GetMousePosition()#
Retrieve the current mouse position.
- Returns:
Mouse position as a Math::Vec2.
-
static Math::Vec2 GetMousePosition(const Window *window)#
Retrieve the current mouse position for the provided window.
- Parameters:
window – Window to check.
- Returns:
Mouse position of the window as a Math::Vec2.
-
static f32 GetMouseX()#
Retrieve the current mouse position on the x axis.
- Returns:
X mouse position.
-
static f32 GetMouseY()#
Retrieve the current mouse position on the y axis.
- Returns:
Y mouse position.
-
static f32 GetMouseX(const Window *window)#
Retrieve the current mouse position on the x axis for the provided window.
- Parameters:
window – Window to check.
- Returns:
X mouse position.
-
static f32 GetMouseY(const Window *window)#
Retrieve the current mouse position on the y axis for the provided window.
- Parameters:
window – Window to check.
- Returns:
Y mouse position.
-
static std::string GetKeyName(Key key)#
Retrieve the string representation of a key.
- Parameters:
key – Key to retrieve.
- Returns:
String representation of the key.
-
static f32 GetControllerAxis(Controller controller, ControllerAxis axis)#
Retrieve the value of the specified controller axis from the provided controller.
- Parameters:
controller – Controller to query.
axis – Controller axis to check.
- Returns:
Value of the axis.
-
static ControllerDPad GetControllerDPad(Controller controller, u32 dpad)#
Retrieve the state of the specified DPad from the provided controller.
- Parameters:
controller – Controller to query.
dpad – DPad to check.
- Returns:
State of the DPad.
-
static ControllerBatteryStatus GetControllerBatteryStatus(Controller controller)#
Retrieve the battery status of the specified controller.
Remark
Windows: This function only works with XInput controllers.
Remark
If controller is not used via XInput then ControllerBatteryStatus::Wired is returned.
- Parameters:
controller – Controller to query.
- Returns:
Status of controller’s battery.
-
static bool IsControllerButtonPressed(Controller controller, ControllerButton button)#
Retrieve whether the specified controller button from the provided controller is pressed or not.
- Parameters:
controller – Controller to query.
button – Controller button to check.
- Returns:
True if controller button is pressed, false otherwise.
-
static std::string GetControllerName(Controller controller)#
Retrieve the name of the provided controller.
- Parameters:
controller – Controller to query.
- Returns:
Name of the controller.
-
static std::string GetControllerGUID(Controller controller)#
Retrieve the GUID of the provided controller.
- Parameters:
controller – Controller to query.
- Returns:
GUID of the controller.
-
static std::vector<f32> GetAllControllerAxes(Controller controller)#
Retrieve all states of all axes from the provided controller.
- Parameters:
controller – Controller to query.
- Returns:
Vector with axes state.
-
static std::vector<bool> GetAllControllerButtons(Controller controller)#
Retrieve all states of every button from the provided controller.
- Parameters:
controller – Controller to query.
- Returns:
Vector with every button state.
-
static std::vector<ControllerDPad> GetAllControllerDPads(Controller controller)#
Retrieve all states of every DPad from the provided controller.
- Parameters:
controller – Controller to query.
- Returns:
Vector with every DPad state.
-
static std::optional<std::string> GetKeyboardLayoutName()#
Retrieve the name of the current keyboard layout.
- Returns:
Name of keyboard layout on success, empty optional otherwise.
-
static void SetControllerVibration(Controller controller, f32 leftMotor, f32 rightMotor)#
Set the vibration level(s) for the specified controller. Intensity values are normalized and range from 0-1.
Remark
Windows: Only takes effect on XInput controllers (DirectInput doesn’t support vibrations).
- Parameters:
controller – Controller to affect.
leftMotor – Normalized intensity for the left motor.
rightMotor – Normalized intensity for the right motor.
-
static void SetControllerVibration(Controller controller, const Math::Vec2 &intensity)#
Set the vibration level(s) for the specified controller. Intensity values are normalized and range from 0-1.
Remark
Windows: Only takes effect on XInput controllers (DirectInput doesn’t support vibrations).
- Parameters:
controller – Controller to affect.
intensity – Normalized intensity for both motors.
-
static void SetMousePosition(f32 x, f32 y)#
Set the mouse position.
- Parameters:
x – New x position.
y – New y position.
-
static void SetMousePosition(f32 x, f32 y, const Window *window)#
Set the mouse position for the provided Window.
- Parameters:
x – New x position.
y – New y position.
window – Window to affect.
-
static void SetMousePosition(const Math::Vec2 &position)#
Set the mouse position.
- Parameters:
position – New position.
-
static void SetMousePosition(const Math::Vec2 &position, const Window *window)#
Set the mouse position for the provided window.
- Parameters:
position – New position.
window – Window to affect.
-
static void SetClipboard(const std::string &str)#
Set the system clipboard to the specified UTF-8 encoded string.
- Parameters:
str – UTF-8 encoded string.
-
static std::string GetClipboard()#
Retrieve the contents of the system clipboard.
- Returns:
Contents of clipboard.
-
static void UpdateControllerMappings(std::string_view map)#
Update an existing Controller mapping or add a new one.
Description: Each mapping is a single line of comma-separated values describing the GUID, name and layout of the Controller. Note: Lines that do not begin with a hexadecimal digit are ignored!
The first value is always the Controller GUID, a 32 character long hexadecimal string that typically identifies its make, model, revision and the type of connection to the computer. When this information is not available, the GUID is generated using the Controller name. TRAP uses the SDL 2.0.5+ GUID format but can convert from the older formats.
The second value is always the human-readable name of the Controller.
All subsequent values are in the form “<field>:<value>” and describe the layout of the mapping. These fields may not all be present and may occur in any order.
The button fields are “a”, “b”, “c”, “d”, “back”, “start”, “guide”, “dpup”, “dpright”, “dpdown”, “dpleft”, “leftshoulder”, “rightshoulder”, “leftstick” and “rightstick”. The axis fields are “leftx”, “lefty”, “rightx”, “righty”, “lefttrigger” and “righttrigger”.
The value of an axis or button field can be a Controller button, a Controller axis, a hat bitmask or empty. Controller buttons are specified as “bN”, for example “b2” for the third button. Controller axes are specified as “aN”, for example “a7” for the eighth axis. Controller hit bit masks are specified as “hN.N”, for example “h0.8” for left on the first hat. More than one bit may be set in the mask.
Before an axis there may be a “+” or “-” range modifier, for example “+a3” for the positive half of the fourth axis. This restricts input to only the positive or negative halves of the Controller axis. After an axis of half-axis there may be the “~” inversion modifier, for example “a2~” or “-a7~”. This negates the values of the Controller axis.
There is also the special “platform” field that specifies which platform the mapping is valid for. Possible values are “Windows” and “Linux”.
- Parameters:
map – Controller mapping to update or add.
-
static EventCallbackFn GetEventCallback() noexcept#
Get the function to call when an input event occurred.
- Returns:
EventCallbackFn.
Friends
- friend class TRAP::Application
- friend class TRAP::INTERNAL::WindowingAPI
-
enum class Key#