logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

process_grave_esc.c (2377B)


  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. #include "keycodes.h"
  18. #include "modifiers.h"
  19. #include "action_util.h"
  20. /* true if the last press of QK_GRAVE_ESCAPE was shifted (i.e. GUI or SHIFT were pressed), false otherwise.
  21. * Used to ensure that the correct keycode is released if the key is released.
  22. */
  23. static bool grave_esc_was_shifted = false;
  24. bool process_grave_esc(uint16_t keycode, keyrecord_t *record) {
  25. if (keycode == QK_GRAVE_ESCAPE) {
  26. const uint8_t mods = get_mods();
  27. uint8_t shifted = mods & MOD_MASK_SG;
  28. #ifdef GRAVE_ESC_ALT_OVERRIDE
  29. // if ALT is pressed, ESC is always sent
  30. // this is handy for the cmd+opt+esc shortcut on macOS, among other things.
  31. if (mods & MOD_MASK_ALT) {
  32. shifted = 0;
  33. }
  34. #endif
  35. #ifdef GRAVE_ESC_CTRL_OVERRIDE
  36. // if CTRL is pressed, ESC is always sent
  37. // this is handy for the ctrl+shift+esc shortcut on windows, among other things.
  38. if (mods & MOD_MASK_CTRL) {
  39. shifted = 0;
  40. }
  41. #endif
  42. #ifdef GRAVE_ESC_GUI_OVERRIDE
  43. // if GUI is pressed, ESC is always sent
  44. if (mods & MOD_MASK_GUI) {
  45. shifted = 0;
  46. }
  47. #endif
  48. #ifdef GRAVE_ESC_SHIFT_OVERRIDE
  49. // if SHIFT is pressed, ESC is always sent
  50. if (mods & MOD_MASK_SHIFT) {
  51. shifted = 0;
  52. }
  53. #endif
  54. if (record->event.pressed) {
  55. grave_esc_was_shifted = shifted;
  56. add_key(shifted ? KC_GRAVE : KC_ESCAPE);
  57. } else {
  58. del_key(grave_esc_was_shifted ? KC_GRAVE : KC_ESCAPE);
  59. }
  60. send_keyboard_report();
  61. return false;
  62. }
  63. // Not a grave keycode so continue processing
  64. return true;
  65. }