From 0b54e7f5ae90ee36e1149b947562e9f7137ec874 Mon Sep 17 00:00:00 2001 From: skullY Date: Tue, 28 Nov 2017 14:08:32 -0800 Subject: [PATCH] Flesh out the grave escape overrides --- docs/_summary.md | 1 + docs/faq_keymap.md | 6 ++---- docs/feature_grave_esc.md | 17 +++++++++++++++++ quantum/quantum.c | 31 +++++++++++++++++++++++++++---- 4 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 docs/feature_grave_esc.md diff --git a/docs/_summary.md b/docs/_summary.md index 3c10e101d1..2c0fc17e36 100644 --- a/docs/_summary.md +++ b/docs/_summary.md @@ -26,6 +26,7 @@ * [Backlight](feature_backlight.md) * [Bootmagic](feature_bootmagic.md) * [Dynamic Macros](feature_dynamic_macros.md) + * [Grave Escape](feature_grave_escape.md) * [Key Lock](feature_key_lock.md) * [Layouts](feature_layouts.md) * [Leader Key](feature_leader_key.md) diff --git a/docs/faq_keymap.md b/docs/faq_keymap.md index 83eeb235ef..6a364eb538 100644 --- a/docs/faq_keymap.md +++ b/docs/faq_keymap.md @@ -125,11 +125,9 @@ https://github.com/tmk/tmk_keyboard/issues/213 https://github.com/tekezo/Karabiner/issues/403 -## Esc and `~ on a key +## Esc and `~ on a single key -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. +See the [Grave Escape](feature_grave_escape.md) feature. ## Arrow on Right Modifier keys with Dual-Role This turns right modifer keys into arrow keys when the keys are tapped while still modifiers when the keys are hold. In TMK the dual-role function is dubbed **TAP**. diff --git a/docs/feature_grave_esc.md b/docs/feature_grave_esc.md new file mode 100644 index 0000000000..ea3c55c639 --- /dev/null +++ b/docs/feature_grave_esc.md @@ -0,0 +1,17 @@ +# Grave Escape + +Grave Escape is a feature that allows you to share the grave key (`\`` and `~`) on the same key as Escape. When `KC_GESC` is used it will act as `KC_ESC`, unless Shift or GUI is pressed, in which case it will act as `KC_GRAVE`. + + +| Key | Alias | Description | +|-----|-------|-------------| +| `GRAVE_ESC` | `KC_GESC` | Act as `KC_ESC` normally, or `KC_GRAVE` when GUI or Shift are held. | + +There are several possible key combinations this will break, among them Ctrl+Shift+Esc on Windows and Cmd+Opt+Esc on macOS. You can use these options in your `config.h` to work around this: + +| Option | Description | +|--------|-------------| +| `GRAVE_ESC_ALT_OVERRIDE` | Always send Escape if Alt is pressed. | +| `GRAVE_ESC_CTRL_OVERRIDE` | Always send Escape if Ctrl is pressed. | +| `GRAVE_ESC_GUI_OVERRIDE` | Always send Escape if GUI is pressed. | +| `GRAVE_ESC_SHIFT_OVERRIDE` | Always send Escape if SHIFT is pressed. | diff --git a/quantum/quantum.c b/quantum/quantum.c index 9232cf4411..d08f15870c 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -548,11 +548,34 @@ bool process_record_quantum(keyrecord_t *record) { 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. - if (get_mods() & (MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL))) +#ifdef GRAVE_ESC_ALT_OVERRIDE + // if ALT is pressed, ESC is always sent + // this is handy for the cmd+opt+esc shortcut on macOS, among other things. + if (get_mods() & (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT))) { shifted = 0; + } +#endif + +#ifdef GRAVE_ESC_CTRL_OVERRIDE + // if CTRL is pressed, ESC is always sent + // this is handy for the ctrl+shift+esc shortcut on windows, among other things. + if (get_mods() & (MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL))) { + shifted = 0; + } +#endif + +#ifdef GRAVE_ESC_GUI_OVERRIDE + // if GUI is pressed, ESC is always sent + if (get_mods() & (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI))) { + shifted = 0; + } +#endif + +#ifdef GRAVE_ESC_SHIFT_OVERRIDE + // if SHIFT is pressed, ESC is always sent + if (get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) { + shifted = 0; + } #endif if (record->event.pressed) {