From aab9c1a4f4a45dc18ddad614f5914bbb5cc19488 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Thu, 1 Feb 2024 21:14:00 +0100 Subject: QMK: Made some key change depending of the previous keys pressed. --- qmk/keyboards/sofle_choc/keymaps/custom/keycodes.c | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) 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 } -- cgit v1.2.3