From 7b8eed9f298e70a88742cefe5d75840160c75435 Mon Sep 17 00:00:00 2001 From: Balz Guenat Date: Fri, 11 Aug 2017 18:53:08 +0200 Subject: [PATCH 1/5] add option to let ctrl override shift/gui for the GRAVE_ESC. This enables the ctrl+shift+esc shortcut to task manager on windows. --- keyboards/bananasplit/keymaps/coloneljesus/config.h | 1 + quantum/quantum.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/keyboards/bananasplit/keymaps/coloneljesus/config.h b/keyboards/bananasplit/keymaps/coloneljesus/config.h index 060f5922f..af6cf8ef1 100644 --- a/keyboards/bananasplit/keymaps/coloneljesus/config.h +++ b/keyboards/bananasplit/keymaps/coloneljesus/config.h @@ -20,5 +20,6 @@ #include "../../config.h" // place overrides here +#define GRAVE_ESC_CTRL_OVERRIDE #endif diff --git a/quantum/quantum.c b/quantum/quantum.c index 1f8ce6c46..8f8cec484 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -475,6 +475,11 @@ bool process_record_quantum(keyrecord_t *record) { 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 (get_mods() & (MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL))) + shifted = 0; +#endif method(shifted ? KC_GRAVE : KC_ESCAPE); send_keyboard_report(); From bd38273f6f48d52374b86d7ff0e7cedfddcb7328 Mon Sep 17 00:00:00 2001 From: Balz Guenat Date: Fri, 11 Aug 2017 21:43:49 +0200 Subject: [PATCH 2/5] add short comment to grave_esc_ctrl_override --- quantum/quantum.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/quantum/quantum.c b/quantum/quantum.c index 8f8cec484..d1969fc5b 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -477,6 +477,8 @@ bool process_record_quantum(keyrecord_t *record) { |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))) shifted = 0; #endif From 3e67cc9c8082871c94739727d9613391eabb4e30 Mon Sep 17 00:00:00 2001 From: Balz Guenat Date: Fri, 11 Aug 2017 22:20:36 +0200 Subject: [PATCH 3/5] add description of new option to docs and add option (commented out) into template. --- docs/faq_keymap.md | 4 +++- quantum/template/config.h | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/faq_keymap.md b/docs/faq_keymap.md index d6442ac53..3c2795816 100644 --- a/docs/faq_keymap.md +++ b/docs/faq_keymap.md @@ -116,7 +116,9 @@ https://github.com/tekezo/Karabiner/issues/403 ## Esc and `~ on a key -Use `GRAVE_ESC` or `KC_GESC` in your keymap. +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. ## 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/quantum/template/config.h b/quantum/template/config.h index dbca45765..700a56f52 100644 --- a/quantum/template/config.h +++ b/quantum/template/config.h @@ -67,6 +67,11 @@ along with this program. If not, see . /* Locking resynchronize hack */ #define LOCKING_RESYNC_ENABLE +/* If defined, GRAVE_ESC will always act as ESC when CTRL is held. + * This is userful for the Windows task manager shortcut (ctrl+shift+esc). + */ +// #define GRAVE_ESC_CTRL_OVERRIDE + /* * Force NKRO * From 175db1a549a46518c2f2511ac1624d594eb07216 Mon Sep 17 00:00:00 2001 From: Balz Guenat Date: Fri, 11 Aug 2017 23:13:50 +0200 Subject: [PATCH 4/5] fix code block formatting --- docs/faq_keymap.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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. From b4be711af1794d2f5eeb4ce1a1db38a1b5d8fd6d Mon Sep 17 00:00:00 2001 From: Balz Guenat Date: Sat, 12 Aug 2017 11:57:42 +0200 Subject: [PATCH 5/5] fix for issue #1568 --- quantum/quantum.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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;