You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.2 KiB

  1. /* Copyright 2020
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "process_grave_esc.h"
  17. /* true if the last press of GRAVE_ESC was shifted (i.e. GUI or SHIFT were pressed), false otherwise.
  18. * Used to ensure that the correct keycode is released if the key is released.
  19. */
  20. static bool grave_esc_was_shifted = false;
  21. bool process_grave_esc(uint16_t keycode, keyrecord_t *record) {
  22. if (keycode == GRAVE_ESC) {
  23. const uint8_t mods = get_mods();
  24. uint8_t shifted = mods & MOD_MASK_SG;
  25. #ifdef GRAVE_ESC_ALT_OVERRIDE
  26. // if ALT is pressed, ESC is always sent
  27. // this is handy for the cmd+opt+esc shortcut on macOS, among other things.
  28. if (mods & MOD_MASK_ALT) {
  29. shifted = 0;
  30. }
  31. #endif
  32. #ifdef GRAVE_ESC_CTRL_OVERRIDE
  33. // if CTRL is pressed, ESC is always sent
  34. // this is handy for the ctrl+shift+esc shortcut on windows, among other things.
  35. if (mods & MOD_MASK_CTRL) {
  36. shifted = 0;
  37. }
  38. #endif
  39. #ifdef GRAVE_ESC_GUI_OVERRIDE
  40. // if GUI is pressed, ESC is always sent
  41. if (mods & MOD_MASK_GUI) {
  42. shifted = 0;
  43. }
  44. #endif
  45. #ifdef GRAVE_ESC_SHIFT_OVERRIDE
  46. // if SHIFT is pressed, ESC is always sent
  47. if (mods & MOD_MASK_SHIFT) {
  48. shifted = 0;
  49. }
  50. #endif
  51. if (record->event.pressed) {
  52. grave_esc_was_shifted = shifted;
  53. add_key(shifted ? KC_GRAVE : KC_ESCAPE);
  54. } else {
  55. del_key(grave_esc_was_shifted ? KC_GRAVE : KC_ESCAPE);
  56. }
  57. send_keyboard_report();
  58. return false;
  59. }
  60. // Not a grave keycode so continue processing
  61. return true;
  62. }