Last active
February 3, 2021 06:09
-
-
Save theol0403/a6a2ccbadf0a4c94be17a7fcee80546e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define NEW_RECORD(press) \ | |
.event = { \ | |
.key = {.col = 254, .row = 254}, \ | |
.time = timer_read() | 1, \ | |
.pressed = press, \ | |
} | |
bool process_combo_key_release(uint16_t combo_index, combo_t *combo, uint8_t key_index, uint16_t keycode) { | |
// count the number of keys that were held down before | |
uint8_t count = __builtin_popcount(combo->state); | |
// if the key being released is the first that breaks the combo | |
if (pgm_read_word(&combo->keys[count]) == COMBO_END) { | |
// loop through all keys that are still held down | |
for (uint8_t i = 0; i < count; ++i) { | |
// don't touch the key that was released | |
if (i == key_index) continue; | |
// get the keycode of the keys still being pressed | |
uint16_t other = pgm_read_word(&combo->keys[i]); | |
switch (other) { | |
case QK_MOD_TAP ... QK_MOD_TAP_MAX: { | |
// in the case that the keycode is a MT, get the mod and apply it | |
uint8_t mod = (other >> 8) & 0x1F; | |
action_tapping_process((keyrecord_t){ | |
NEW_RECORD(true), | |
.keycode = MT(mod, KC_NO), | |
}); | |
break; | |
} | |
case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: { | |
// in the case that the keycode is a LT, get the layer and apply it | |
uint8_t layer = (other >> 8) & 0x1F; | |
action_tapping_process((keyrecord_t){ | |
NEW_RECORD(true), | |
.keycode = LT(layer, KC_NO), | |
}); | |
break; | |
} | |
} | |
} | |
} else { | |
// release all the tap-holds one by one | |
switch (keycode) { | |
case QK_MOD_TAP ... QK_MOD_TAP_MAX: { | |
uint8_t mod = (keycode >> 8) & 0x1F; | |
action_tapping_process((keyrecord_t){ | |
NEW_RECORD(false), | |
.keycode = MT(mod, KC_NO), | |
}); | |
break; | |
} | |
case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: { | |
uint8_t layer = (keycode >> 8) & 0x1F; | |
action_tapping_process((keyrecord_t){ | |
NEW_RECORD(false), | |
.keycode = LT(layer, KC_NO), | |
}); | |
break; | |
} | |
} | |
} | |
return false; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define NEW_RECORD(press) \ | |
.event = { \ | |
.key = {.col = 254, .row = 254}, \ | |
.time = timer_read() | 1, \ | |
.pressed = press, \ | |
} | |
bool process_combo_key_release(uint16_t combo_index, combo_t *combo, uint8_t key_index, uint16_t keycode) { | |
// count the number of keys that were held down before | |
uint8_t count = __builtin_popcount(combo->state); | |
// if the key being released is the first that breaks the combo | |
if (pgm_read_word(&combo->keys[count]) == COMBO_END) { | |
// loop through all keys that are still held down | |
for (uint8_t i = 0; i < count; ++i) { | |
// don't touch the key that was released | |
if (i == key_index) continue; | |
// get the keycode of the keys still being pressed | |
uint16_t other = pgm_read_word(&combo->keys[i]); | |
switch (other) { | |
case QK_MOD_TAP ... QK_MOD_TAP_MAX: | |
case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: | |
// process the tap-hold, while making the keycode = KC_NO | |
action_tapping_process((keyrecord_t){NEW_RECORD(true), .keycode = other & 0xFF00}); | |
} | |
} | |
} else { | |
// release all the tap-holds one by one | |
switch (keycode) { | |
case QK_MOD_TAP ... QK_MOD_TAP_MAX: | |
case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: | |
action_tapping_process((keyrecord_t){NEW_RECORD(false), .keycode = keycode & 0xFF00}); | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment