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.

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