tapdances.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //Tap Dance Settings
  2. #include "wanleg.h"
  3. ///// QUAD FUNCTION TAP DANCE GENERAL SETUP SECTION START /////
  4. ///// (no need to edit this section) /////
  5. //Enums used to clearly convey the state of the tap dance
  6. enum {
  7. SINGLE_TAP = 1,
  8. SINGLE_HOLD = 2,
  9. DOUBLE_TAP = 3,
  10. DOUBLE_HOLD = 4,
  11. DOUBLE_SINGLE_TAP = 5 //send SINGLE_TAP twice - NOT DOUBLE_TAP
  12. // Add more enums here if you want for triple, quadruple, etc.
  13. };
  14. typedef struct {
  15. bool is_press_action;
  16. int state;
  17. } tap;
  18. int cur_dance (qk_tap_dance_state_t *state) {
  19. if (state->count == 1) {
  20. //If count = 1, and it has been interrupted - it doesn't matter if it is pressed or not: Send SINGLE_TAP
  21. if (state->interrupted || !state->pressed) return SINGLE_TAP;
  22. if (state->interrupted) return SINGLE_TAP;
  23. else return SINGLE_HOLD;
  24. }
  25. //If count = 2, and it has been interrupted - assume that user is trying to type the letter associated
  26. //with single tap.
  27. else if (state->count == 2) {
  28. if (state->interrupted) return DOUBLE_SINGLE_TAP;
  29. else if (state->pressed) return DOUBLE_HOLD;
  30. else return DOUBLE_TAP;
  31. }
  32. else return 6; //magic number. At some point this method will expand to work for more presses
  33. }
  34. ///// QUAD FUNCTION TAP DANCE GENERAL SETUP SECTION END /////
  35. ///// QUAD FUNCTION TAP DANCE PERSONALIZATION SECTION START /////
  36. //instantialize an instance of 'tap' for the 'ENT' tap dance.
  37. static tap ENTtap_state = {
  38. .is_press_action = true,
  39. .state = 0
  40. };
  41. void ENT_finished (qk_tap_dance_state_t *state, void *user_data) {
  42. ENTtap_state.state = cur_dance(state);
  43. switch (ENTtap_state.state) {
  44. case SINGLE_TAP: register_code(KC_SPC); break;
  45. case SINGLE_HOLD: register_code(KC_LSFT); break;
  46. case DOUBLE_TAP: register_code(KC_ENT); break;
  47. case DOUBLE_HOLD: register_code(KC_NO); break; // setting double hold to do nothing (change this if you want)
  48. case DOUBLE_SINGLE_TAP: register_code(KC_SPC); unregister_code(KC_SPC); register_code(KC_SPC);
  49. //Last case is for fast typing. Assuming your key is `f`:
  50. //For example, when typing the word `buffer`, and you want to make sure that you send `ff` and not `Esc`.
  51. //In order to type `ff` when typing fast, the next character will have to be hit within the `TAPPING_TERM`, which by default is 200ms.
  52. }
  53. }
  54. void ENT_reset (qk_tap_dance_state_t *state, void *user_data) {
  55. switch (ENTtap_state.state) {
  56. case SINGLE_TAP: unregister_code(KC_SPC); break;
  57. case SINGLE_HOLD: unregister_code(KC_LSFT); break;
  58. case DOUBLE_TAP: unregister_code(KC_ENT); break;
  59. case DOUBLE_HOLD: unregister_code(KC_NO);
  60. case DOUBLE_SINGLE_TAP: unregister_code(KC_SPC);
  61. }
  62. ENTtap_state.state = 0;
  63. }
  64. //instanalize an instance of 'tap' for the 'DEL' tap dance.
  65. static tap DELtap_state = {
  66. .is_press_action = true,
  67. .state = 0
  68. };
  69. void DEL_finished (qk_tap_dance_state_t *state, void *user_data) {
  70. DELtap_state.state = cur_dance(state);
  71. switch (DELtap_state.state) {
  72. case SINGLE_TAP: register_code(KC_BSPC); break;
  73. case SINGLE_HOLD: register_code(KC_LCTL); break;
  74. case DOUBLE_TAP: register_code(KC_DEL); break;
  75. case DOUBLE_HOLD: register_code(KC_NO); break;
  76. case DOUBLE_SINGLE_TAP: register_code(KC_BSPC); unregister_code(KC_BSPC); register_code(KC_BSPC);
  77. }
  78. }
  79. void DEL_reset (qk_tap_dance_state_t *state, void *user_data) {
  80. switch (DELtap_state.state) {
  81. case SINGLE_TAP: unregister_code(KC_BSPC); break;
  82. case SINGLE_HOLD: unregister_code(KC_LCTL); break;
  83. case DOUBLE_TAP: unregister_code(KC_DEL); break;
  84. case DOUBLE_HOLD: unregister_code(KC_NO);
  85. case DOUBLE_SINGLE_TAP: unregister_code(KC_BSPC);
  86. }
  87. DELtap_state.state = 0;
  88. }
  89. ///// QUAD FUNCTION TAP DANCE PERSONALIZATION SECTION END /////
  90. //Tap Dance Definitions
  91. //THIS SECTION HAS TO BE AT THE END OF THE TAP DANCE SECTION
  92. qk_tap_dance_action_t tap_dance_actions[] = {
  93. [TD_SFT_CAPS] = ACTION_TAP_DANCE_DOUBLE(KC_LSFT, KC_CAPS)
  94. // Other declarations would go here, separated by commas, if you have them
  95. ,[TD_Q_ESC] = ACTION_TAP_DANCE_DOUBLE(KC_Q, KC_ESC)
  96. ,[ENT_TAP_DANCE] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, ENT_finished, ENT_reset)
  97. ,[DEL_TAP_DANCE] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, DEL_finished, DEL_reset)
  98. };
  99. //In Layer declaration, add tap dance item in place of a key code
  100. //TD(TD_SFT_CAPS)