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