#include QMK_KEYBOARD_H #include "keymap_bepo.h" #include "quad_tapdance.h" #include "shift_dance.h" // // Definition for the key W. // // The main usage is to send the letter W when pressed, but the key is also // used to activate the SHIFT mode when pressed. // static td_tap_t right_shift_tap_state = { .state = TD_NONE }; // Do not switch the supended mode when the key is released. // This allow to remove the mod earler without reactivating automatically. static bool inhibit_mod = 0; static bool lshift_interrupted = 0; // If there is any other keypress before releasing the key, do not keep the // layer once the key is release. // // This function is a callbackk called from process_record_user void shift_dance_process_record(uint16_t keycode, keyrecord_t *record) { if (right_shift_tap_state.state == TD_SINGLE_HOLD && record->event.pressed) { // If there is any key pressed while holding the key, do not switch // in caps lock mod on release. inhibit_mod = 1; } switch (keycode) { // If the key is pressed without any other combination, remove the // caps lock if activated. // Otherwise, act just as a modifier key. case KC_LSFT: if (record->event.pressed) { lshift_interrupted = 0; break; } if (lshift_interrupted) { break; } // Continue on the next block case KC_ESC: if (host_keyboard_led_state().caps_lock) { tap_code16(KC_CAPS_LOCK); } break; default: lshift_interrupted = 1; break; } return; } void right_shift_finished(tap_dance_state_t *state, void *user_data) { right_shift_tap_state.state = cur_dance(state); switch (right_shift_tap_state.state) { case TD_SINGLE_HOLD: if (get_mods() & MOD_MASK_SHIFT) { del_mods(MOD_MASK_SHIFT); inhibit_mod = 1; } register_code(KC_RIGHT_SHIFT); break; default: break; } } void right_shift_released(tap_dance_state_t *state, void *user_data) { if (state->finished && state->count > 1) // Exit prevently, we are sure in the next conditions we don’t fall in // this case. return; else if (!state->finished) tap_code16(BP_W); else if (!state->interrupted && !inhibit_mod) { // Final case, the key was keeped pressed without any other action // in this case, switch into CAPS LOCK del_mods(MOD_MASK_SHIFT); tap_code16(KC_CAPS_LOCK); } inhibit_mod = 0; } void right_shift_reset(tap_dance_state_t *state, void *user_data) { switch (right_shift_tap_state.state) { case TD_SINGLE_HOLD: unregister_code(KC_RIGHT_SHIFT); break; default: break; } right_shift_tap_state.state = TD_NONE; }