forked from Ikcelaks/qmk_sequence_transform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeybuffer.h
More file actions
36 lines (31 loc) · 1.55 KB
/
keybuffer.h
File metadata and controls
36 lines (31 loc) · 1.55 KB
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
// Copyright 2021 Google LLC
// Copyright 2021 @filterpaper
// Copyright 2023 Pablo Martinez (@elpekenin) <elpekenin@elpekenin.dev>
// Copyright 2024 Guillaume Stordeur <guillaume.stordeur@gmail.com>
// Copyright 2024 Matt Skalecki <ikcelaks@gmail.com>
// Copyright 2024 QKekos <q.kekos.q@gmail.com>
// SPDX-License-Identifier: Apache-2.0
// Original source/inspiration: https://getreuer.info/posts/keyboards/autocorrection
#pragma once
//////////////////////////////////////////////////////////////////
// Public API
#define ST_DEFAULT_KEY_ACTION 0xffff
typedef struct
{
uint16_t keypressed;
uint16_t action_taken;
} st_key_action_t;
typedef struct
{
st_key_action_t * const data; // array of keycodes
const int size; // buffer size (TODO: rename to capacity)
int context_len; // number of current keys in buffer (TODO: rename to size)
int cur_pos; // current head for circular access
} st_key_buffer_t;
st_key_action_t *st_key_buffer_get(const st_key_buffer_t *buf, int index);
uint16_t st_key_buffer_get_keycode(const st_key_buffer_t *buf, int index);
void st_key_buffer_reset(st_key_buffer_t *buf);
void st_key_buffer_push(st_key_buffer_t *buf, uint16_t keycode);
void st_key_buffer_pop(st_key_buffer_t *buf, uint8_t num);
void st_key_buffer_print(const st_key_buffer_t *buf);
void st_key_buffer_to_str(const st_key_buffer_t *buf, char *output_string, uint8_t len);