MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Keys.cpp
Go to the documentation of this file.
1#include "Keys.hpp"
2
4
5namespace MayaFlux::IO {
6
7namespace {
8 constexpr std::array<std::pair<char, Keys>, 10> char_to_keys = { {
9 { ' ', Keys::Space },
10 { '\'', Keys::Apostrophe },
11 { ',', Keys::Comma },
12 { '-', Keys::Minus },
13 { '.', Keys::Period },
14 { '/', Keys::Slash },
15 { ';', Keys::Semicolon },
16 { '=', Keys::Equal },
17 { '[', Keys::LeftBracket },
18 { ']', Keys::RightBracket },
19 } };
20}
21
22std::optional<Keys> from_char(char c) noexcept
23{
24 for (const auto& [ch, key] : char_to_keys) {
25 if (ch == c)
26 return key;
27 }
28
29 if (c >= '0' && c <= '9') {
30 return static_cast<Keys>(static_cast<int>(c));
31 }
32 if (c >= 'A' && c <= 'Z') {
33 return static_cast<Keys>(static_cast<int>(c));
34 }
35 if (c >= 'a' && c <= 'z') {
36 return static_cast<Keys>(static_cast<int>(c) - 32);
37 }
38
39 return std::nullopt;
40}
41
42std::optional<Keys> from_string(std::string_view str) noexcept
43{
44 if (str.empty()) {
45 return std::nullopt;
46 }
47
48 if (str.length() == 1) {
49 return from_char(str[0]);
50 }
51
52 return Reflect::string_to_enum_case_insensitive<Keys>(str);
53}
54
55std::string_view to_string(Keys key) noexcept
56{
57 return Reflect::enum_to_string(key);
58}
59
60std::string to_lowercase_string(Keys key) noexcept
61{
63}
64
65bool is_printable(Keys key) noexcept
66{
67 int k = static_cast<int>(key);
68 return k >= 32 && k <= 126; // Standard printable ASCII range
69}
70
71bool is_modifier(Keys key) noexcept
72{
73 return key == Keys::LShift || key == Keys::RShift || key == Keys::LCtrl || key == Keys::RCtrl || key == Keys::LAlt || key == Keys::RAlt || key == Keys::LSuper || key == Keys::RSuper;
74}
75
76bool is_function_key(Keys key) noexcept
77{
78 int k = static_cast<int>(key);
79 return k >= 290 && k <= 314; // F1-F25
80}
81
82bool is_keypad_key(Keys key) noexcept
83{
84 int k = static_cast<int>(key);
85 return k >= 320 && k <= 336; // KP0-KPEqual
86}
87
88std::vector<std::string> all_key_names_lowercase() noexcept
89{
90 return Reflect::get_enum_names_lowercase<Keys>();
91}
92
93auto all_key_names() noexcept
94{
95 return Reflect::get_enum_names<Keys>();
96}
97
98auto all_keys() noexcept
99{
100 return Reflect::get_enum_values<Keys>();
101}
102
103size_t key_count() noexcept
104{
105 return Reflect::enum_count<Keys>();
106}
107
108} // namespace MayaFlux::IO
bool is_modifier(Keys key) noexcept
Checks if a key is a modifier key (e.g., Shift, Ctrl, Alt).
Definition Keys.cpp:71
std::vector< std::string > all_key_names_lowercase() noexcept
Returns a vector of all key names in lowercase.
Definition Keys.cpp:88
size_t key_count() noexcept
Returns the total number of keys.
Definition Keys.cpp:103
bool is_printable(Keys key) noexcept
Checks if a key is a printable character.
Definition Keys.cpp:65
std::string to_lowercase_string(Keys key) noexcept
Converts a Keys enum value to its lowercase string representation.
Definition Keys.cpp:60
std::optional< Keys > from_char(char c) noexcept
Converts a character to the corresponding Keys enum value.
Definition Keys.cpp:22
bool is_function_key(Keys key) noexcept
Checks if a key is a function key (e.g., F1-F25).
Definition Keys.cpp:76
std::optional< Keys > from_string(std::string_view str) noexcept
Converts a string to the corresponding Keys enum value.
Definition Keys.cpp:42
auto all_key_names() noexcept
Returns a container of all key names.
Definition Keys.cpp:93
std::string_view to_string(Keys key) noexcept
Converts a Keys enum value to its string representation.
Definition Keys.cpp:55
auto all_keys() noexcept
Returns a container of all Keys enum values.
Definition Keys.cpp:98
bool is_keypad_key(Keys key) noexcept
Checks if a key is a keypad key.
Definition Keys.cpp:82
std::string enum_to_lowercase_string(EnumType value) noexcept
Universal enum to lowercase string converter using magic_enum.
constexpr std::string_view enum_to_string(EnumType value) noexcept
Universal enum to string converter using magic_enum (original case)