aboutsummaryrefslogtreecommitdiff
path: root/src/keyboard/inc/keyboard.h
blob: 8bae4d3aad86be76a385c4db5511c4eb9b3337c1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef KEYBOARD_H
#define KEYBOARD_H

#include <keyboard/key.h>
#include <keyboard/combo.h>
#include <keyboard/port.h>
#include <stdbool.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C"
{
#endif

#define KEYBOARD_COMBO(...) (const struct keyboard_combo){.keys = {__VA_ARGS__}}

struct keyboard
{
    struct keyboard_input
    {
        struct keyboard_combo
        {
            enum keyboard_key keys[KEYBOARD_MAX_COMBO_KEYS];
        } combo;

        struct keyboard_chars
        {
            char c[KEYBOARD_MAX_COMBO_KEYS];
        } chars;
    } input, oldinput;

    size_t i;
    struct keyboard_port port;
};

void keyboard_init(struct keyboard *k);
void keyboard_update(struct keyboard *k);
bool keyboard_available(void);
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);
bool keyboard_any_justpressed(const struct keyboard *k, struct keyboard_input *in);
bool keyboard_any_pressed(const struct keyboard *k, struct keyboard_input *in);
const char *keyboard_key_str(enum keyboard_key k);

#ifdef __cplusplus
}
#endif

#endif /* KEYBOARD_H */