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.

127 lines
4.5 KiB

  1. // Copyright 2021-2022 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. //
  16. // Caps Word, activated by pressing both shift keys at the same time.
  17. //
  18. // This library implements "Caps Word", which is like conventional Caps Lock,
  19. // but automatically disables itself at the end of the word. This is useful for
  20. // typing all-caps identifiers like `MOD_MASK_ALT`.
  21. //
  22. // Caps Word is activated by pressing the left and right shift keys at the same
  23. // time. This way you don't need a dedicated key for using Caps Word. I've
  24. // tested that this works as expected with one-shot mods and Space Cadet Shift.
  25. // If your shift keys are mod-taps, activate Caps Word by holding both shift
  26. // mod-tap keys until the tapping term, release them, then begin typing.
  27. //
  28. // Optionally, Caps Word may be configured to deactivate if the keyboard is idle
  29. // for some time. This is useful to mitigate unintended shifting when you get
  30. // interrupted or switch to the mouse while Caps Word is active. In your
  31. // config.h, define `CAPS_WORD_IDLE_TIMEOUT` with a time in milliseconds:
  32. //
  33. // #define CAPS_WORD_IDLE_TIMEOUT 5000 // Turn off Caps Word after 5 seconds.
  34. //
  35. // and in your keymap.c, define (or add to) `matrix_scan_user()` as
  36. //
  37. // void matrix_scan_user(void) {
  38. // caps_word_task();
  39. // // Other tasks...
  40. // }
  41. //
  42. // For full documentation, see
  43. // https://getreuer.info/posts/keyboards/caps-word
  44. #pragma once
  45. #include QMK_KEYBOARD_H
  46. // Call this function from `process_record_user()` to implement Caps Word.
  47. bool process_caps_word(uint16_t keycode, keyrecord_t* record);
  48. // If CAPS_WORD_IDLE_TIMEOUT is set, call `caps_word_task()` from
  49. // `matrix_scan_user()` as described above.
  50. //
  51. // If CAPS_WORD_IDLE_TIMEOUT isn't set, calling this function has no effect (but
  52. // will still compile).
  53. #if CAPS_WORD_IDLE_TIMEOUT > 0
  54. void caps_word_task(void);
  55. #else
  56. static inline void caps_word_task(void) {}
  57. #endif
  58. // Activates or deactivates Caps Word. For instance activate Caps Word with a
  59. // combo by defining a `COMBO_ACTION` that calls `caps_word_set(true)`:
  60. //
  61. // void process_combo_event(uint16_t combo_index, bool pressed) {
  62. // switch(combo_index) {
  63. // case CAPS_COMBO:
  64. // if (pressed) {
  65. // caps_word_set(true); // Activate Caps Word.
  66. // }
  67. // break;
  68. //
  69. // // Other combos...
  70. // }
  71. // }
  72. void caps_word_set(bool active);
  73. // Returns whether Caps Word is currently active.
  74. bool caps_word_get(void);
  75. // An optional callback that gets called when Caps Word turns on or off. This is
  76. // useful to represent the current Caps Word state, e.g. by setting an LED or
  77. // playing a sound. In your keymap, define
  78. //
  79. // void caps_word_set_user(bool active) {
  80. // if (active) {
  81. // // Do something when Caps Word activates.
  82. // } else {
  83. // // Do something when Caps Word deactivates.
  84. // }
  85. // }
  86. void caps_word_set_user(bool active);
  87. // An optional callback which is called on every key press while Caps Word is
  88. // active. When the key should be shifted (that is, a letter key), the callback
  89. // should call `add_weak_mods(MOD_BIT(KC_LSFT))` to shift the key. The callback
  90. // also determines whether the key should continue Caps Word. Returning true
  91. // continues the current "word", while returning false is "word breaking" and
  92. // deactivates Caps Word. The default callback is
  93. //
  94. // bool caps_word_press_user(uint16_t keycode) {
  95. // switch (keycode) {
  96. // // Keycodes that continue Caps Word, with shift applied.
  97. // case KC_A ... KC_Z:
  98. // add_weak_mods(MOD_BIT(KC_LSFT)); // Apply shift to the next key.
  99. // return true;
  100. //
  101. // // Keycodes that continue Caps Word, without shifting.
  102. // case KC_1 ... KC_0:
  103. // case KC_BSPC:
  104. // case KC_MINS:
  105. // case KC_UNDS:
  106. // return true;
  107. //
  108. // default:
  109. // return false; // Deactivate Caps Word.
  110. // }
  111. // }
  112. //
  113. // To customize, copy the above function into your keymap and add/remove
  114. // keycodes to the above cases.
  115. //
  116. // NOTE: Outside of this callback, you can use `caps_word_set(false)` to
  117. // deactivate Caps Word.
  118. bool caps_word_press_user(uint16_t keycode);