diff --git a/docs/faq_keymap.md b/docs/faq_keymap.md index 3c2795816..0d24a7667 100644 --- a/docs/faq_keymap.md +++ b/docs/faq_keymap.md @@ -116,7 +116,7 @@ https://github.com/tekezo/Karabiner/issues/403 ## Esc and `~ on a key -Use `GRAVE_ESC` or `KC_GESC` in your keymap. `GUI`+`GRAVE_ESC` results in `\`` and `SHIFT`+`GRAVE_ESC` results in `~`. +Use `GRAVE_ESC` or `KC_GESC` in your keymap. `GUI`+`GRAVE_ESC` results in `` ` `` and `SHIFT`+`GRAVE_ESC` results in `~`. Note that this will break the CTRL+SHIFT+ESC shortcut to the Windows task manager. Use `#define GRAVE_ESC_CTRL_OVERRIDE` in your `config.h` to get the shortcut back. With this option, `ESC_GRAVE` results in `ESC` if `CTRL` is held, even if `SHIFT` or `GUI` are also held. diff --git a/quantum/quantum.c b/quantum/quantum.c index aac1d07a9..65213eaea 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -161,6 +161,11 @@ void reset_keyboard(void) { static bool shift_interrupted[2] = {0, 0}; static uint16_t scs_timer[2] = {0, 0}; +/* true if the last press of GRAVE_ESC was shifted (i.e. GUI or SHIFT were pressed), false otherwise. + * Used to ensure that the correct keycode is released if the key is released. + */ +static bool grave_esc_was_shifted = false; + bool process_record_quantum(keyrecord_t *record) { /* This gets the keycode from the key pressed */ @@ -475,10 +480,9 @@ bool process_record_quantum(keyrecord_t *record) { // break; } case GRAVE_ESC: { - void (*method)(uint8_t) = (record->event.pressed) ? &add_key : &del_key; uint8_t shifted = get_mods() & ((MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT) |MOD_BIT(KC_LGUI)|MOD_BIT(KC_RGUI))); - + #ifdef GRAVE_ESC_CTRL_OVERRIDE // if CTRL is pressed, ESC is always read as ESC, even if SHIFT or GUI is pressed. // this is handy for the ctrl+shift+esc shortcut on windows, among other things. @@ -486,8 +490,15 @@ bool process_record_quantum(keyrecord_t *record) { shifted = 0; #endif - method(shifted ? KC_GRAVE : KC_ESCAPE); - send_keyboard_report(); + if (record->event.pressed) { + grave_esc_was_shifted = shifted; + add_key(shifted ? KC_GRAVE : KC_ESCAPE); + } + else { + del_key(grave_esc_was_shifted ? KC_GRAVE : KC_ESCAPE); + } + + send_keyboard_report(); } default: { shift_interrupted[0] = true;