libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
keyevent.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
13#include <promeki/event.h>
14#include <promeki/string.h>
15
16PROMEKI_NAMESPACE_BEGIN
17
25class KeyEvent : public Event {
26 public:
28 static const Type KeyPress;
30 static const Type KeyRelease;
31
33 enum Key {
34 Key_Unknown = 0,
35 // Printable ASCII range handled by char value
36 Key_Space = 32,
37 // Control keys
38 Key_Escape = 256,
39 Key_Enter,
40 Key_Tab,
41 Key_Backspace,
42 Key_Insert,
43 Key_Delete,
44 Key_Home,
45 Key_End,
46 Key_PageUp,
47 Key_PageDown,
48 // Arrow keys
49 Key_Up,
50 Key_Down,
51 Key_Left,
52 Key_Right,
53 // Function keys
54 Key_F1,
55 Key_F2,
56 Key_F3,
57 Key_F4,
58 Key_F5,
59 Key_F6,
60 Key_F7,
61 Key_F8,
62 Key_F9,
63 Key_F10,
64 Key_F11,
65 Key_F12
66 };
67
69 enum Modifier : uint8_t {
70 NoModifier = 0x00,
71 ShiftModifier = 0x01,
72 CtrlModifier = 0x02,
73 AltModifier = 0x04,
74 MetaModifier = 0x08
75 };
76
84 KeyEvent(Type type, Key key, uint8_t modifiers = NoModifier, const String &text = String())
85 : Event(type), _key(key), _modifiers(modifiers), _text(text) {}
86
88 Key key() const { return _key; }
89
91 uint8_t modifiers() const { return _modifiers; }
92
94 const String &text() const { return _text; }
95
97 bool isShift() const { return _modifiers & ShiftModifier; }
98
100 bool isCtrl() const { return _modifiers & CtrlModifier; }
101
103 bool isAlt() const { return _modifiers & AltModifier; }
104
106 bool isMeta() const { return _modifiers & MetaModifier; }
107
109 static String keyName(Key key);
110
112 static String modifierString(uint8_t modifiers);
113
114 private:
115 Key _key;
116 uint8_t _modifiers;
117 String _text;
118};
119
120PROMEKI_NAMESPACE_END
121
122#endif // PROMEKI_ENABLE_CORE