diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-02-24 17:55:57 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-03-30 08:20:21 +0200 |
| commit | 9eee43d3bb24000077602a62dfdfeee2606f1589 (patch) | |
| tree | 0e5f8efef62b068e252fe9c98c14fec723e0a7a3 /src/keyboard/inc | |
| parent | 18717569acda82b26099c62410df3b398d596ba1 (diff) | |
| download | rts-9eee43d3bb24000077602a62dfdfeee2606f1589.tar.gz | |
Add support for keyboard and mouse
Diffstat (limited to 'src/keyboard/inc')
| -rw-r--r-- | src/keyboard/inc/keyboard.h | 38 | ||||
| -rw-r--r-- | src/keyboard/inc/keyboard_key.h | 70 |
2 files changed, 108 insertions, 0 deletions
diff --git a/src/keyboard/inc/keyboard.h b/src/keyboard/inc/keyboard.h new file mode 100644 index 0000000..5c53ba8 --- /dev/null +++ b/src/keyboard/inc/keyboard.h @@ -0,0 +1,38 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +#include <keyboard_key.h> +#include <stdbool.h> +#include <stddef.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define KEYBOARD_COMBO(...) (const struct keyboard_combo){.keys = {__VA_ARGS__}} + +enum {KEYBOARD_MAX_COMBO_KEYS = 3}; + +struct keyboard +{ + struct keyboard_combo + { + enum keyboard_key keys[KEYBOARD_MAX_COMBO_KEYS]; + } combo, oldcombo; + + size_t i; +}; + +void keyboard_init(struct keyboard *k); +void keyboard_update(struct keyboard *k); +bool keyboard_justpressed(const struct keyboard *k, const struct keyboard_combo *c); +bool keyboard_pressed(const struct keyboard *k, const struct keyboard_combo *c); +bool keyboard_justreleased(const struct keyboard *k, const struct keyboard_combo *c); +const char *keyboard_key_str(enum keyboard_key k); + +#ifdef __cplusplus +} +#endif + +#endif /* KEYBOARD_H */ diff --git a/src/keyboard/inc/keyboard_key.h b/src/keyboard/inc/keyboard_key.h new file mode 100644 index 0000000..337a09f --- /dev/null +++ b/src/keyboard/inc/keyboard_key.h @@ -0,0 +1,70 @@ +#ifndef KEYBOARD_KEYS_H +#define KEYBOARD_KEYS_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define KEYBOARD_KEYS \ + X(KEYBOARD_KEY_NONE) \ + X(KEYBOARD_KEY_A) \ + X(KEYBOARD_KEY_B) \ + X(KEYBOARD_KEY_C) \ + X(KEYBOARD_KEY_D) \ + X(KEYBOARD_KEY_E) \ + X(KEYBOARD_KEY_F) \ + X(KEYBOARD_KEY_G) \ + X(KEYBOARD_KEY_H) \ + X(KEYBOARD_KEY_I) \ + X(KEYBOARD_KEY_J) \ + X(KEYBOARD_KEY_K) \ + X(KEYBOARD_KEY_L) \ + X(KEYBOARD_KEY_M) \ + X(KEYBOARD_KEY_N) \ + X(KEYBOARD_KEY_O) \ + X(KEYBOARD_KEY_P) \ + X(KEYBOARD_KEY_Q) \ + X(KEYBOARD_KEY_R) \ + X(KEYBOARD_KEY_S) \ + X(KEYBOARD_KEY_T) \ + X(KEYBOARD_KEY_U) \ + X(KEYBOARD_KEY_V) \ + X(KEYBOARD_KEY_W) \ + X(KEYBOARD_KEY_X) \ + X(KEYBOARD_KEY_Y) \ + X(KEYBOARD_KEY_Z) \ + X(KEYBOARD_KEY_0) \ + X(KEYBOARD_KEY_1) \ + X(KEYBOARD_KEY_2) \ + X(KEYBOARD_KEY_3) \ + X(KEYBOARD_KEY_4) \ + X(KEYBOARD_KEY_5) \ + X(KEYBOARD_KEY_6) \ + X(KEYBOARD_KEY_7) \ + X(KEYBOARD_KEY_8) \ + X(KEYBOARD_KEY_9) \ + X(KEYBOARD_KEY_LSHIFT) \ + X(KEYBOARD_KEY_RSHIFT) \ + X(KEYBOARD_KEY_LCTRL) \ + X(KEYBOARD_KEY_RCTRL) \ + X(KEYBOARD_KEY_F11) \ + X(KEYBOARD_KEY_ESC) \ + X(KEYBOARD_KEY_LEFT) \ + X(KEYBOARD_KEY_RIGHT) \ + X(KEYBOARD_KEY_UP) \ + X(KEYBOARD_KEY_DOWN) \ + X(KEYBOARD_KEY_EXIT) + +enum keyboard_key +{ +#define X(x) x, + KEYBOARD_KEYS +#undef X +}; + +#ifdef __cplusplus +} +#endif + +#endif /* KEYBOARD_KEYS_H */ |
