libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
keyevent.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <promeki/core/event.h>
11#include <promeki/core/string.h>
12
14
22class KeyEvent : public Event {
23 public:
25 static const Type KeyPress;
27 static const Type KeyRelease;
28
30 enum Key {
31 Key_Unknown = 0,
32 // Printable ASCII range handled by char value
33 Key_Space = 32,
34 // Control keys
35 Key_Escape = 256,
36 Key_Enter,
37 Key_Tab,
38 Key_Backspace,
39 Key_Insert,
40 Key_Delete,
41 Key_Home,
42 Key_End,
43 Key_PageUp,
44 Key_PageDown,
45 // Arrow keys
46 Key_Up,
47 Key_Down,
48 Key_Left,
49 Key_Right,
50 // Function keys
51 Key_F1, Key_F2, Key_F3, Key_F4,
52 Key_F5, Key_F6, Key_F7, Key_F8,
53 Key_F9, Key_F10, Key_F11, Key_F12
54 };
55
58 NoModifier = 0x00,
59 ShiftModifier = 0x01,
60 CtrlModifier = 0x02,
61 AltModifier = 0x04,
62 MetaModifier = 0x08
63 };
64
73 const String &text = String())
74 : Event(type), _key(key), _modifiers(modifiers), _text(text) {}
75
77 Key key() const { return _key; }
78
80 uint8_t modifiers() const { return _modifiers; }
81
83 const String &text() const { return _text; }
84
86 bool isShift() const { return _modifiers & ShiftModifier; }
87
89 bool isCtrl() const { return _modifiers & CtrlModifier; }
90
92 bool isAlt() const { return _modifiers & AltModifier; }
93
95 bool isMeta() const { return _modifiers & MetaModifier; }
96
99
102
103 private:
104 Key _key;
105 uint8_t _modifiers;
106 String _text;
107};
108
Base class for the event system.
Definition event.h:29
Type type() const
Returns the type identifier for this event.
Definition event.h:71
Event delivered when a key is pressed or released.
Definition keyevent.h:22
Key key() const
Returns the key code.
Definition keyevent.h:77
static const Type KeyPress
Event type ID for KeyEvent.
Definition keyevent.h:25
uint8_t modifiers() const
Returns the modifier flags.
Definition keyevent.h:80
Key
Key code enumeration.
Definition keyevent.h:30
static const Type KeyRelease
Event type ID for KeyRelease (rarely used in TUI).
Definition keyevent.h:27
Modifier
Modifier flags.
Definition keyevent.h:57
bool isCtrl() const
Returns true if the Ctrl modifier is set.
Definition keyevent.h:89
static String keyName(Key key)
Returns a human-readable name for the given key code.
bool isMeta() const
Returns true if the Meta modifier is set.
Definition keyevent.h:95
static String modifierString(uint8_t modifiers)
Returns a human-readable string for the given modifier flags (e.g. "Ctrl+Shift+").
bool isShift() const
Returns true if the Shift modifier is set.
Definition keyevent.h:86
bool isAlt() const
Returns true if the Alt modifier is set.
Definition keyevent.h:92
const String & text() const
Returns the printable text.
Definition keyevent.h:83
KeyEvent(Type type, Key key, uint8_t modifiers=NoModifier, const String &text=String())
Constructs a KeyEvent.
Definition keyevent.h:72
Dynamic array container wrapping std::vector.
Definition list.h:40
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19