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.

166 lines
6.5 KiB

  1. # Caps Word
  2. It is often useful to type a single word in all capitals, for instance
  3. abbreviations like "QMK", or in code, identifiers like `KC_SPC`. "Caps Word" is
  4. a modern alternative to Caps Lock:
  5. * Letters are capitalized while active, and Caps Word automatically disables
  6. itself at the end of the word. That is, it stops by default once a space or
  7. any key other than `KC_A`--`KC_Z`, `KC_0`--`KC_9`, `KC_MINS`, `KC_UNDS`,
  8. `KC_DELETE`, or `KC_BACKSPACE` is pressed. Caps Word also disables itself if
  9. the keyboard is idle for 5 seconds. This is configurable, see below.
  10. * To avoid requiring a dedicated key for Caps Word, there is an option
  11. (`BOTH_SHIFTS_TURNS_ON_CAPS_WORD`) to activate Caps Word by simultaneously
  12. pressing both shift keys. See below for other options.
  13. * The implementation does not use the Caps Lock (`KC_CAPS`) keycode. Caps Word
  14. works even if you're remapping Caps Lock at the OS level to Ctrl or something
  15. else, as Emacs and Vim users often do. As a consequence, Caps Word does not
  16. follow the typical Caps Lock behaviour and may thus act in potentially
  17. unexpected ways, especially when using an *OS* keyboard layout other than US
  18. or UK. For example, Dvorak's <kbd>, <</kbd> key (`DV_COMM` aka `KC_W`) will
  19. get shifted because Caps Word interprets that keycode as the letter 'W' by
  20. default, the Spanish <kbd>Ñ</kbd> key (`ES_NTIL` aka `KC_SCLN`) will not get
  21. capitalized because Caps Word interprets it as the semicolon ';' punctuation
  22. character, and the US hyphen key (`KC_MINS`), while unaffected by Caps Lock,
  23. is shifted by Caps Word. However, this is not really a problem because you can
  24. [configure which keys should Caps Word
  25. shift](#configure-which-keys-are-word-breaking).
  26. ## How do I enable Caps Word :id=how-do-i-enable-caps-word
  27. In your `rules.mk`, add:
  28. ```make
  29. CAPS_WORD_ENABLE = yes
  30. ```
  31. Next, use one the following methods to activate Caps Word:
  32. * **Activate by pressing a key**: Use the `CAPS_WORD` keycode (short
  33. alias `CAPSWRD`) in your keymap.
  34. * **Activate by pressing Left Shift + Right Shift**: Add `#define
  35. BOTH_SHIFTS_TURNS_ON_CAPS_WORD` to config.h. You may also need to disable or
  36. reconfigure Command, details below. Then, simultaneously pressing both left
  37. and right shifts turns on Caps Word. This method works with the plain
  38. `KC_LSFT` and `KC_RSFT` keycodes as well as one-shot shifts and Space Cadet
  39. shifts. If your shift keys are mod-taps, hold both shift mod-tap keys until
  40. the tapping term, then release them.
  41. * **Activate by double tapping Left Shift**: Add `#define
  42. DOUBLE_TAP_SHIFT_TURNS_ON_CAPS_WORD` config.h. Then, double tapping Left Shift
  43. turns on Caps Word. This method works with `KC_LSFT` or one-shot Left Shift
  44. `OSM(MOD_LSFT)`. To count as a double tap, the maximum time in milliseconds
  45. between taps is `TAPPING_TERM`, or if using `TAPPING_TERM_PER_KEY`, the time
  46. returned by `get_tapping_term()` for the shift keycode being tapped.
  47. * **Custom activation**: You can activate Caps Word from code by calling
  48. `caps_word_on()`. This may be used to activate Caps Word through [a
  49. combo](feature_combo.md) or [tap dance](feature_tap_dance.md) or any means
  50. you like.
  51. ### Troubleshooting: Command :id=troubleshooting-command
  52. When using `BOTH_SHIFTS_TURNS_ON_CAPS_WORD`, you might see a compile message
  53. **"BOTH_SHIFTS_TURNS_ON_CAPS_WORD and Command should not be enabled at the same
  54. time, since both use the Left Shift + Right Shift key combination."**
  55. Many keyboards enable the [Command feature](feature_command.md), which by
  56. default is also activated using the Left Shift + Right Shift key combination. To
  57. fix this conflict, please disable Command by adding in rules.mk:
  58. ```make
  59. COMMAND_ENABLE = no
  60. ```
  61. Or configure Command to use another key combination like Left Ctrl + Right Ctrl
  62. by defining `IS_COMMAND()` in config.h:
  63. ```c
  64. // Activate Command with Left Ctrl + Right Ctrl.
  65. #define IS_COMMAND() (get_mods() == MOD_MASK_CTRL)
  66. ```
  67. ## Customizing Caps Word :id=customizing-caps-word
  68. ### Idle timeout :id=idle-timeout
  69. Caps Word turns off automatically if no keys are pressed for
  70. `CAPS_WORD_IDLE_TIMEOUT` milliseconds. The default is 5000 (5 seconds).
  71. Configure the timeout duration in config.h, for instance
  72. ```c
  73. #define CAPS_WORD_IDLE_TIMEOUT 3000 // 3 seconds.
  74. ```
  75. Setting `CAPS_WORD_IDLE_TIMEOUT` to 0 configures Caps Word to never time out.
  76. Caps Word then remains active indefinitely until a word breaking key is pressed.
  77. ### Functions :id=functions
  78. Functions to manipulate Caps Word:
  79. | Function | Description |
  80. |-------------------------|------------------------------------------------|
  81. | `caps_word_on()` | Turns Caps Word on. |
  82. | `caps_word_off()` | Turns Caps Word off. |
  83. | `caps_word_toggle()` | Toggles Caps Word. |
  84. | `is_caps_word_on()` | Returns true if Caps Word is currently on. |
  85. ### Configure which keys are "word breaking" :id=configure-which-keys-are-word-breaking
  86. You can define the `caps_word_press_user(uint16_t keycode)` callback to
  87. configure which keys should be shifted and which keys are considered "word
  88. breaking" and stop Caps Word.
  89. The callback is called on every key press while Caps Word is active. When the
  90. key should be shifted (that is, a letter key), the callback should call
  91. `add_weak_mods(MOD_BIT(KC_LSFT))` to shift the key. Returning true continues the
  92. current "word," while returning false is "word breaking" and deactivates Caps
  93. Word. The default callback is
  94. ```c
  95. bool caps_word_press_user(uint16_t keycode) {
  96. switch (keycode) {
  97. // Keycodes that continue Caps Word, with shift applied.
  98. case KC_A ... KC_Z:
  99. case KC_MINS:
  100. add_weak_mods(MOD_BIT(KC_LSFT)); // Apply shift to next key.
  101. return true;
  102. // Keycodes that continue Caps Word, without shifting.
  103. case KC_1 ... KC_0:
  104. case KC_BSPC:
  105. case KC_DEL:
  106. case KC_UNDS:
  107. return true;
  108. default:
  109. return false; // Deactivate Caps Word.
  110. }
  111. }
  112. ```
  113. ### Representing Caps Word state :id=representing-caps-word-state
  114. Define `caps_word_set_user(bool active)` to get callbacks when Caps Word turns
  115. on or off. This is useful to represent the current Caps Word state, e.g. by
  116. setting an LED or playing a sound. In your keymap, define
  117. ```c
  118. void caps_word_set_user(bool active) {
  119. if (active) {
  120. // Do something when Caps Word activates.
  121. } else {
  122. // Do something when Caps Word deactivates.
  123. }
  124. }
  125. ```