custom_double_taps.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. }