Toast Engine
Loading...
Searching...
No Matches
keycodes.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
9#include <cstdint>
10#include <string_view>
11#include <toast/export.hpp>
12
13namespace input {
14
18enum class Device : uint8_t {
19 none,
20 keyboard,
21 mouse,
22 controller,
23};
24
28enum class ModifierKey : uint8_t {
29 none = 0,
30 shift = 0b001,
31 control = 0b010,
32 alt = 0b100,
33};
34
35[[nodiscard]]
36constexpr auto operator|(ModifierKey a, ModifierKey b) -> ModifierKey {
37 return static_cast<ModifierKey>(static_cast<uint8_t>(a) | static_cast<uint8_t>(b));
38}
39
40[[nodiscard]]
41constexpr auto operator&(ModifierKey a, ModifierKey b) -> ModifierKey {
42 return static_cast<ModifierKey>(static_cast<uint8_t>(a) & static_cast<uint8_t>(b));
43}
44
48enum class InputKind : uint8_t {
54};
55
63struct KeyCode {
64 Device device = Device::none;
66 int code = 0;
67 bool valid = false;
68};
69
71constexpr int controller_stick_left = 0;
72constexpr int controller_stick_right = 1;
73constexpr int controller_touchpad = 2;
74
76constexpr int controller_gyro_x = 100;
77constexpr int controller_gyro_y = 101;
78constexpr int controller_gyro_z = 102;
79
85[[nodiscard]]
86auto TOAST_API parseKeycode(std::string_view str) -> KeyCode;
87
88}
auto parseKeycode(std::string_view str) -> KeyCode
Parses a textual keycode such as "keyboard/a", "mouse/left" or "controller/left_stick".
Definition keycodes.cpp:264
ModifierKey
Bit flags for the keyboard modifier keys held during an input.
Definition keycodes.hpp:28
constexpr int controller_gyro_x
Gyro axis codes used as the code for the controller gyro_x/y/z inputs.
Definition keycodes.hpp:76
constexpr int controller_stick_left
Controller stick indices used as the code for InputKind::axis2d controller inputs.
Definition keycodes.hpp:71
InputKind
Dimensionality of an input, used by the input system to pick a sampling path.
Definition keycodes.hpp:48
@ scroll
mouse wheel; code 0 is vertical, code 1 is horizontal
Definition keycodes.hpp:52
@ cursor
mouse cursor position or delta
Definition keycodes.hpp:53
@ axis1d
single-axis analog input such as a trigger or one stick axis
Definition keycodes.hpp:50
@ axis2d
two-axis analog input such as a full stick or the touchpad
Definition keycodes.hpp:51
@ button
on/off input such as a key or a gamepad button
Definition keycodes.hpp:49
Device
Physical device a keycode belongs to.
Definition keycodes.hpp:18
A parsed keycode resolved to a device, kind and numeric code.
Definition keycodes.hpp:63