Skip to content

Commit

Permalink
feat: return false if keyboard has no keycodes down
Browse files Browse the repository at this point in the history
  • Loading branch information
headblockhead committed Aug 30, 2024
1 parent ab9aee7 commit 4835bd6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions include/squirrel_keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ void keyboard_activate_keycode(uint8_t keycode);
void keyboard_deactivate_keycode(uint8_t keycode);
// keyboard_get_keycodes populates the provided array with the first 6 active
// keycodes. 6 is the maximum number of keycodes that
// can be sent over USB HID.
void keyboard_get_keycodes(uint8_t (*active_keycodes)[6]);
// can be sent over USB HID. It also returns true if there are any active
// keycodes.
bool keyboard_get_keycodes(uint8_t (*active_keycodes)[6]);

// keyboard_activate_modifier marks the provided modifier as active.
void keyboard_activate_modifier(uint8_t modifier);
Expand Down
3 changes: 2 additions & 1 deletion src/squirrel_keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void keyboard_activate_keycode(uint8_t keycode) {
void keyboard_deactivate_keycode(uint8_t keycode) {
keyboard_keycodes[keycode] = false;
}
void keyboard_get_keycodes(uint8_t (*active_keycodes)[6]) {
bool keyboard_get_keycodes(uint8_t (*active_keycodes)[6]) {
uint8_t active_keycodes_index = 0;
for (int i = 0; (i <= 0xFF) && active_keycodes_index < 6; i++) {
if (!keyboard_keycodes[i]) {
Expand All @@ -20,6 +20,7 @@ void keyboard_get_keycodes(uint8_t (*active_keycodes)[6]) {
(*active_keycodes)[active_keycodes_index] = i;
active_keycodes_index++;
}
return active_keycodes_index > 0;
}

void keyboard_activate_modifier(uint8_t modifier) {
Expand Down

0 comments on commit 4835bd6

Please sign in to comment.