-
Notifications
You must be signed in to change notification settings - Fork 1
/
capsword.c
54 lines (48 loc) · 1.32 KB
/
capsword.c
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
51
52
53
54
// CAPS WORD by dnaq, iaap and others.
// Borrowed from @sevanteri.
#pragma once
#include <stdbool.h>
static bool caps_word_enabled = false;
void caps_word_enable(void) {
caps_word_enabled = true;
if (!host_keyboard_led_state().caps_lock) {
tap_code(KC_CAPS);
}
}
void caps_word_disable(void) {
caps_word_enabled = false;
if (host_keyboard_led_state().caps_lock) {
tap_code(KC_CAPS);
}
}
void caps_word_toggle(void) {
if (caps_word_enabled) {
caps_word_disable();
} else {
caps_word_enable();
}
}
static void process_caps_word(uint16_t keycode, keyrecord_t *record) {
if (caps_word_enabled) {
// first strip of the mod taps and layer taps if needed
switch (keycode) {
case QK_MOD_TAP ... QK_MOD_TAP_MAX:
case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
if (record->tap.count == 0)
return;
keycode = keycode & 0xFF;
}
// we end caps word on one of the following keypresses
switch (keycode & 0xFF) {
case KC_ESC:
case KC_SPC:
case KC_ENT:
case KC_TAB:
case KC_DOT:
case KC_COMM:
if (record->event.pressed) {
caps_word_disable();
}
}
}
}