diff options
author | Sébastien Dailly <sebastien@dailly.me> | 2024-02-01 21:14:00 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2024-02-01 21:14:00 +0100 |
commit | aab9c1a4f4a45dc18ddad614f5914bbb5cc19488 (patch) | |
tree | 169285c5aadc7313fc1198b53b753c4f7585bd0e /qmk/keyboards/sofle_choc/keymaps | |
parent | 2881787aeac52549bd457c93a5a31b572b68c6de (diff) |
QMK: Made some key change depending of the previous keys pressed.
Diffstat (limited to 'qmk/keyboards/sofle_choc/keymaps')
-rw-r--r-- | qmk/keyboards/sofle_choc/keymaps/custom/keycodes.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/keycodes.c b/qmk/keyboards/sofle_choc/keymaps/custom/keycodes.c index bd091bb..069f5e2 100644 --- a/qmk/keyboards/sofle_choc/keymaps/custom/keycodes.c +++ b/qmk/keyboards/sofle_choc/keymaps/custom/keycodes.c @@ -97,8 +97,21 @@ uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { } } +static uint32_t key_timer; // timer for last keyboard activity, use + // 32bit value and function to make longer + // idle time possible +static uint16_t latest_key; bool process_record_user(uint16_t keycode, keyrecord_t *record) { + + + if (!record->event.pressed) { + // store time of last key release. This is used as a counter in order to + // know if we are inside a typing sequence or not. + key_timer = timer_read32(); + latest_key = keycode; + } + switch (keycode) { case AL_ENT: if (layer_state_is(LAYER_SYMBOLS) && !record->event.pressed) { @@ -106,6 +119,33 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { layer_clear(); } return true; // Let QMK send the enter press/release events + // If a key where released just before, consider we are typing some text + // and not starting a new sequence + case KEY_E: + if (record->event.pressed && timer_elapsed32(key_timer) < TAPPING_TERM) { + register_code(BP_E); + return false; + } + return true; + case KEY_T: + if (record->event.pressed && timer_elapsed32(key_timer) < TAPPING_TERM) { + register_code(BP_T); + return false; + } + return true; + // Here, the key KC_BSPC become È when used inside a sequence, but we still + // allow the repetition of KC_BSPC. + case KC_BSPC: + if (record->event.pressed \ + && timer_elapsed32(key_timer) < TAPPING_TERM \ + && latest_key != keycode) + { + // I completely rewrite the key here, that’s why I’m using tap_code16 + // instead of register_code. + tap_code16(BP_EGRV); + return false; + } + return true; default: return true; // Process all other keycodes normally } |