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