This only applies to keymaps that has combined esc/grave. Here we call it theKEY.
Think about the motion when we do shift + theKEY (typing ~), or CMD + theKEY (switching window on MAC). Based on the original code, we must do following sequence: press shift -> press theKEY -> release theKEY -> release shift. However, it is very possible and natural that we do this stroke sequence instead: press shift -> press theKEY -> release shift -> release theKEY.
If we do the 2nd stroke sequence, the code will del_key(ESC) instead of (GRV) when we release theKEY. This caused some inconvenient issues and ghost typing.
By adding a flag, this issue is eliminated and will not affect any other functions.
void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {
static uint8_t mods_pressed;
+ static bool mods_flag;
switch (id) {
case 0:
*/
if (mods_pressed) {
add_key(KC_GRV);
+ mod_flag = true;
send_keyboard_report();
} else {
add_key(KC_ESC);
} else {
/* The key is being released.
*/
- if (mods_pressed) {
+ if (mod_flag) {
del_key(KC_GRV);
+ mod_flag = false;
send_keyboard_report();
} else {
del_key(KC_ESC);