MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
KeyMapping.cpp
Go to the documentation of this file.
1#include "KeyMapping.hpp"
2
3namespace MayaFlux::Core {
4
5IO::Keys from_glfw_key(int glfw_key) noexcept
6{
7 if (glfw_key < -1 || glfw_key > 348) {
9 }
10
11 auto result = static_cast<IO::Keys>(glfw_key);
12
13 if (!is_valid_glfw_key(glfw_key)) {
14 return IO::Keys::Unknown;
15 }
16
17 return result;
18}
19
20int to_glfw_key(IO::Keys key) noexcept
21{
22 return static_cast<int>(key);
23}
24
25bool is_valid_glfw_key(int glfw_key) noexcept
26{
27 // GLFW only generates specific key codes;
28 // Supported ranges based on Keys enum:
29 // - 32-126: Printable ASCII
30 // - 256-269: Navigation/editing
31 // - 280-284: Lock keys
32 // - 290-314: Function keys (F1-F25)
33 // - 320-336: Keypad
34 // - 340-348: Modifiers and menu
35
36 if (glfw_key == -1) {
37 return false;
38 }
39
40 if (glfw_key >= 32 && glfw_key <= 126) {
41 return true; // Printable ASCII range
42 }
43
44 if (glfw_key >= 256 && glfw_key <= 269) {
45 return true; // Escape through End
46 }
47
48 if (glfw_key >= 280 && glfw_key <= 284) {
49 return true; // Lock keys
50 }
51
52 if (glfw_key >= 290 && glfw_key <= 314) {
53 return true; // F1-F25
54 }
55
56 if (glfw_key >= 320 && glfw_key <= 336) {
57 return true; // Keypad
58 }
59
60 if (glfw_key >= 340 && glfw_key <= 348) {
61 return true; // Modifiers and Menu
62 }
63
64 return false;
65}
66
67} // namespace MayaFlux::Core
int to_glfw_key(IO::Keys key) noexcept
Convert a MayaFlux Keys enum to GLFW key code.
IO::Keys from_glfw_key(int glfw_key) noexcept
Convert a GLFW key code to MayaFlux Keys enum.
Definition KeyMapping.cpp:5
bool is_valid_glfw_key(int glfw_key) noexcept
Check if a GLFW key code is valid/supported.