custom_double_taps.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright 2022 Google LLC
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "gourdo1.h"
  5. static bool process_capsnum(uint16_t keycode, keyrecord_t * record) {
  6. static bool toggled = false;
  7. static bool tapped = false;
  8. static uint16_t tap_timer = 0;
  9. if (keycode == CAPSNUM) {
  10. if (user_config.double_tap_shift_for_capslock) {
  11. // Act as TT(_NUMPADMOUSE)
  12. if (record -> event.pressed) { // CAPSNUM key was pressed
  13. // Check whether the key was recently tapped
  14. if (tapped && !timer_expired(record -> event.time, tap_timer)) {
  15. // This is a double tap (or possibly a triple tap or more)
  16. // Toggle the layer on.
  17. toggled = true;
  18. } else if (toggled) {
  19. // Otherwise if currently toggled, turn it off
  20. toggled = false;
  21. tapped = false;
  22. layer_off(_NUMPADMOUSE);
  23. }
  24. // Set that the first tap occurred in a potential double tap
  25. tapped = true;
  26. tap_timer = record -> event.time + TAPPING_TERM;
  27. layer_on(_NUMPADMOUSE);
  28. } else if (!toggled) {
  29. // If not currently toggled, turn off on key release
  30. layer_off(_NUMPADMOUSE);
  31. return false;
  32. }
  33. } else { // When double_tap_shift_for_capslock == false
  34. // Act as KC_CAPS
  35. if (record -> event.pressed) {
  36. register_code(KC_CAPS);
  37. } else {
  38. unregister_code(KC_CAPS);
  39. }
  40. }
  41. return false;
  42. } else {
  43. // On an event with any other key, reset the double tap state
  44. tapped = false;
  45. }
  46. return true;
  47. }
  48. static bool process_esc_to_base(uint16_t keycode, keyrecord_t * record) {
  49. static bool tapped = false;
  50. static uint16_t tap_timer = 0;
  51. if (keycode == KC_ESC) {
  52. if (user_config.esc_double_tap_to_baselyr) {
  53. if (record -> event.pressed) {
  54. if (tapped && !timer_expired(record -> event.time, tap_timer)) {
  55. // The key was double tapped.
  56. layer_clear();
  57. }
  58. tapped = true;
  59. tap_timer = record -> event.time + TAPPING_TERM;
  60. }
  61. }
  62. } else {
  63. // On an event with any other key, reset the double tap state.
  64. tapped = false;
  65. }
  66. return true;
  67. }
  68. static bool process_lsft_for_caps(uint16_t keycode, keyrecord_t * record) {
  69. static bool tapped = false;
  70. static uint16_t tap_timer = 0;
  71. if (keycode == KC_LSFT) {
  72. if (user_config.double_tap_shift_for_capslock) {
  73. if (!keymap_config.no_gui) {
  74. if (record->event.pressed) {
  75. if (tapped && !timer_expired(record->event.time, tap_timer)) {
  76. // The key was double tapped.
  77. //clear_mods(); // If needed, clear the mods.
  78. // Do something interesting...
  79. register_code(KC_CAPS);
  80. }
  81. tapped = true;
  82. tap_timer = record->event.time + TAPPING_TERM;
  83. } else {
  84. unregister_code(KC_CAPS);
  85. }
  86. }
  87. }
  88. } else {
  89. // On an event with any other key, reset the double tap state.
  90. tapped = false;
  91. }
  92. return true;
  93. }