From 06558064013c61477a41c0821586c4443638cc2b Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sun, 3 Aug 2025 16:34:25 -0400 Subject: liboda: input: Add constant 'ODA_KEY_*' defines Signed-off-by: Ian Moffett --- lib/liboda/include/liboda/input.h | 13 ++++++++++++- lib/liboda/src/input.c | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/liboda/include/liboda/input.h b/lib/liboda/include/liboda/input.h index 9906329..7ba2670 100644 --- a/lib/liboda/include/liboda/input.h +++ b/lib/liboda/include/liboda/input.h @@ -30,7 +30,6 @@ #ifndef LIBODA_INPUT_H #define LIBODA_INPUT_H -#include #include #include @@ -41,13 +40,25 @@ #define ODA_SCANCODE(KEY) ((KEY) >> 8) #define ODA_KEYCHAR(KEY) ((char )(KEY) & 0xFF) +/* + * Key defines + */ +#define ODA_KEY_OTHER 0x0000 +#define ODA_KEY_ESCAPE 0x0001 +#define ODA_KEY_TAB 0x0002 +#define ODA_KEY_BACKSPACE 0x0003 +#define ODA_KEY_ALPHA 0x0004 +#define ODA_KEY_NUM 0x0005 + /* * Represents a key press * + * @type: Key types (see ODA_KEY_*) * @scancode: Scancode * @ch: Character */ struct oda_key { + uint16_t type; uint8_t scancode; char ch; }; diff --git a/lib/liboda/src/input.c b/lib/liboda/src/input.c index 88c4256..797a9d4 100644 --- a/lib/liboda/src/input.c +++ b/lib/liboda/src/input.c @@ -27,12 +27,38 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include #include +#include #include #include #include #include +/* + * Convert key scancode/char values to fixed + * ODA key constants + */ +static inline uint16_t +oda_map_key(const struct oda_key *key) +{ + uint16_t type = ODA_KEY_OTHER; + + switch (key->ch) { + case ASCII_ESC: + type = ODA_KEY_ESCAPE; + break; + case ASCII_HT: + type = ODA_KEY_TAB; + break; + case ASCII_BS: + type = ODA_KEY_BACKSPACE; + break; + } + + return type; +} + /* * Dispatch keyboard events. This is typically * called in an event loop so that keyboard events @@ -57,5 +83,6 @@ oda_kbd_dispatch(struct oda_kbd *kbd) key.scancode = ODA_SCANCODE(input); key.ch = ODA_KEYCHAR(input); + key.type = oda_map_key(&key); return kbd->handle_keyev(kbd, &key); } -- cgit v1.2.3