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.

347 lines
13 KiB

  1. # Auto Shift: Why Do We Need a Shift Key?
  2. Tap a key and you get its character. Tap a key, but hold it *slightly* longer
  3. and you get its shifted state. Voilร ! No shift key needed!
  4. ## Why Auto Shift?
  5. Many people suffer from various forms of RSI. A common cause is stretching your
  6. fingers repetitively long distances. For us on the keyboard, the pinky does that
  7. all too often when reaching for the shift key. Auto Shift looks to alleviate that
  8. problem.
  9. ## How Does It Work?
  10. When you tap a key, it stays depressed for a short period of time before it is
  11. then released. This depressed time is a different length for everyone. Auto Shift
  12. defines a constant `AUTO_SHIFT_TIMEOUT` which is typically set to twice your
  13. normal pressed state time. When you press a key, a timer starts, and if you
  14. have not released the key after the `AUTO_SHIFT_TIMEOUT` period, then a shifted
  15. version of the key is emitted. If the time is less than the `AUTO_SHIFT_TIMEOUT`
  16. time, or you press another key, then the normal state is emitted.
  17. If `AUTO_SHIFT_REPEAT` is defined, there is keyrepeat support. Holding the key
  18. down will repeat the shifted key, though this can be disabled with
  19. `AUTO_SHIFT_NO_AUTO_REPEAT`. If you want to repeat the normal key, then tap it
  20. once then immediately (within `TAPPING_TERM`) hold it down again (this works
  21. with the shifted value as well if auto-repeat is disabled).
  22. There are also the `get_auto_shift_repeat` and `get_auto_shift_no_auto_repeat`
  23. functions for more granular control. Neither will have an effect unless
  24. `AUTO_SHIFT_REPEAT_PER_KEY` or `AUTO_SHIFT_NO_AUTO_REPEAT_PER_KEY` respectively
  25. are defined.
  26. ## Are There Limitations to Auto Shift?
  27. Yes, unfortunately.
  28. 1. You will have characters that are shifted when you did not intend on shifting, and
  29. other characters you wanted shifted, but were not. This simply comes down to
  30. practice. As we get in a hurry, we think we have hit the key long enough for a
  31. shifted version, but we did not. On the other hand, we may think we are tapping
  32. the keys, but really we have held it for a little longer than anticipated.
  33. 2. Additionally, with keyrepeat the desired shift state can get mixed up. It will
  34. always 'belong' to the last key pressed. For example, keyrepeating a capital
  35. and then tapping something lowercase (whether or not it's an Auto Shift key)
  36. will result in the capital's *key* still being held, but shift not.
  37. 3. Auto Shift does not apply to Tap Hold keys. For automatic shifting of Tap Hold
  38. keys see [Retro Shift](#retro-shift).
  39. ## How Do I Enable Auto Shift?
  40. Add to your `rules.mk` in the keymap folder:
  41. AUTO_SHIFT_ENABLE = yes
  42. If no `rules.mk` exists, you can create one.
  43. Then compile and install your new firmware with Auto Key enabled! That's it!
  44. ## Modifiers
  45. By default, Auto Shift is disabled for any key press that is accompanied by one or more
  46. modifiers. Thus, Ctrl+A that you hold for a really long time is not the same
  47. as Ctrl+Shift+A.
  48. You can re-enable Auto Shift for modifiers by adding a define to your `config.h`
  49. ```c
  50. #define AUTO_SHIFT_MODIFIERS
  51. ```
  52. In which case, Ctrl+A held past the `AUTO_SHIFT_TIMEOUT` will be sent as Ctrl+Shift+A
  53. ## Configuring Auto Shift
  54. If desired, there is some configuration that can be done to change the
  55. behavior of Auto Shift. This is done by setting various variables the
  56. `config.h` file located in your keymap folder. If no `config.h` file exists, you can create one.
  57. A sample is
  58. ```c
  59. #pragma once
  60. #define AUTO_SHIFT_TIMEOUT 150
  61. #define NO_AUTO_SHIFT_SPECIAL
  62. ```
  63. ### AUTO_SHIFT_TIMEOUT (Value in ms)
  64. This controls how long you have to hold a key before you get the shifted state.
  65. Obviously, this is different for everyone. For the common person, a setting of
  66. 135 to 150 works great. However, one should start with a value of at least 175, which
  67. is the default value. Then work down from there. The idea is to have the shortest time required to get the shifted state without having false positives.
  68. Play with this value until things are perfect. Many find that all will work well
  69. at a given value, but one or two keys will still emit the shifted state on
  70. occasion. This is simply due to habit and holding some keys a little longer
  71. than others. Once you find this value, work on tapping your problem keys a little
  72. quicker than normal and you will be set.
  73. ?> Auto Shift has three special keys that can help you get this value right very quick. See "Auto Shift Setup" for more details!
  74. For more granular control of this feature, you can add the following to your `config.h`:
  75. ```c
  76. #define AUTO_SHIFT_TIMEOUT_PER_KEY
  77. ```
  78. You can then add the following function to your keymap:
  79. ```c
  80. uint16_t get_autoshift_timeout(uint16_t keycode, keyrecord_t *record) {
  81. switch(keycode) {
  82. case AUTO_SHIFT_NUMERIC:
  83. return 2 * get_generic_autoshift_timeout();
  84. case AUTO_SHIFT_SPECIAL:
  85. return get_generic_autoshift_timeout() + 50;
  86. case AUTO_SHIFT_ALPHA:
  87. default:
  88. return get_generic_autoshift_timeout();
  89. }
  90. }
  91. ```
  92. Note that you cannot override individual keys that are in one of those groups
  93. if you are using them; trying to add a case for `KC_A` in the above example will
  94. not compile as `AUTO_SHIFT_ALPHA` is there. A possible solution is a second switch
  95. above to handle individual keys with no default case and only referencing the
  96. groups in the below fallback switch.
  97. ### NO_AUTO_SHIFT_SPECIAL (simple define)
  98. Do not Auto Shift special keys, which include -\_, =+, [{, ]}, ;:, '", ,<, .>,
  99. and /?
  100. ### NO_AUTO_SHIFT_NUMERIC (simple define)
  101. Do not Auto Shift numeric keys, zero through nine.
  102. ### NO_AUTO_SHIFT_ALPHA (simple define)
  103. Do not Auto Shift alpha characters, which include A through Z.
  104. ### Auto Shift Per Key
  105. There are functions that allows you to determine which keys shold be autoshifted, much like the tap-hold keys.
  106. The first of these, used to simply add a key to Auto Shift, is `get_custom_auto_shifted_key`:
  107. ```c
  108. bool get_custom_auto_shifted_key(uint16_t keycode, keyrecord_t *record) {
  109. switch(keycode) {
  110. case KC_DOT:
  111. return true;
  112. default:
  113. return false;
  114. }
  115. }
  116. ```
  117. For more granular control, there is `get_auto_shifted_key`. The default function looks like this:
  118. ```c
  119. bool get_auto_shifted_key(uint16_t keycode, keyrecord_t *record) {
  120. switch (keycode) {
  121. # ifndef NO_AUTO_SHIFT_ALPHA
  122. case KC_A ... KC_Z:
  123. # endif
  124. # ifndef NO_AUTO_SHIFT_NUMERIC
  125. case KC_1 ... KC_0:
  126. # endif
  127. # ifndef NO_AUTO_SHIFT_SPECIAL
  128. case KC_TAB:
  129. case KC_MINUS ... KC_SLASH:
  130. case KC_NONUS_BACKSLASH:
  131. # endif
  132. return true;
  133. }
  134. return get_custom_auto_shifted_key(keycode, record);
  135. }
  136. ```
  137. This functionality is enabled by default, and does not need a define.
  138. ### AUTO_SHIFT_REPEAT (simple define)
  139. Enables keyrepeat.
  140. ### AUTO_SHIFT_NO_AUTO_REPEAT (simple define)
  141. Disables automatically keyrepeating when `AUTO_SHIFT_TIMEOUT` is exceeded.
  142. ## Custom Shifted Values
  143. Especially on small keyboards, the default shifted value for many keys is not
  144. optimal. To provide more customizability, there are two user-definable
  145. functions, `autoshift_press/release_user`. These register or unregister the
  146. correct value for the passed key. Below is an example adding period to Auto
  147. Shift and making its shifted value exclamation point. Make sure to use weak
  148. mods - setting real would make any keys following it use their shifted values
  149. as if you were holding the key. Clearing of modifiers is handled by Auto Shift,
  150. and the OS-sent shift value if keyrepeating multiple keys is always that of
  151. the last key pressed (whether or not it's an Auto Shift key).
  152. You can also have non-shifted keys for the shifted values (or even no shifted
  153. value), just don't set a shift modifier!
  154. ```c
  155. bool get_custom_auto_shifted_key(uint16_t keycode, keyrecord_t *record) {
  156. switch(keycode) {
  157. case KC_DOT:
  158. return true;
  159. default:
  160. return false;
  161. }
  162. }
  163. void autoshift_press_user(uint16_t keycode, bool shifted, keyrecord_t *record) {
  164. switch(keycode) {
  165. case KC_DOT:
  166. register_code16((!shifted) ? KC_DOT : KC_EXLM);
  167. break;
  168. default:
  169. if (shifted) {
  170. add_weak_mods(MOD_BIT(KC_LSFT));
  171. }
  172. // & 0xFF gets the Tap key for Tap Holds, required when using Retro Shift
  173. register_code16((IS_RETRO(keycode)) ? keycode & 0xFF : keycode);
  174. }
  175. }
  176. void autoshift_release_user(uint16_t keycode, bool shifted, keyrecord_t *record) {
  177. switch(keycode) {
  178. case KC_DOT:
  179. unregister_code16((!shifted) ? KC_DOT : KC_EXLM);
  180. break;
  181. default:
  182. // & 0xFF gets the Tap key for Tap Holds, required when using Retro Shift
  183. // The IS_RETRO check isn't really necessary here, always using
  184. // keycode & 0xFF would be fine.
  185. unregister_code16((IS_RETRO(keycode)) ? keycode & 0xFF : keycode);
  186. }
  187. }
  188. ```
  189. ## Retro Shift
  190. Holding and releasing a Tap Hold key without pressing another key will ordinarily
  191. result in only the hold. With `retro shift` enabled this action will instead
  192. produce a shifted version of the tap keycode on release.
  193. It does not require [Retro Tapping](tap_hold.md#retro-tapping) to be enabled, and
  194. if both are enabled the state of `retro tapping` will only apply if the tap keycode
  195. is not matched by Auto Shift. `RETRO_TAPPING_PER_KEY` and its corresponding
  196. function, however, are checked before `retro shift` is applied.
  197. To enable `retro shift`, add the following to your `config.h`:
  198. ```c
  199. #define RETRO_SHIFT
  200. ```
  201. If `RETRO_SHIFT` is defined to a value, hold times greater than that value will
  202. not produce a tap on release for Mod Taps, and instead triggers the hold action.
  203. This enables modifiers to be held for combining with mouse clicks without
  204. generating taps on release. For example:
  205. ```c
  206. #define RETRO_SHIFT 500
  207. ```
  208. This value (if set) must be greater than one's `TAPPING_TERM`, as the key press
  209. must be designated as a 'hold' by `process_tapping` before we send the modifier.
  210. There is no such limitation in regards to `AUTO_SHIFT_TIMEOUT` for normal keys.
  211. ### Retro Shift and Tap Hold Configurations
  212. Tap Hold Configurations work a little differently when using Retro Shift.
  213. Referencing `TAPPING_TERM` makes little sense, as holding longer would result in
  214. shifting one of the keys.
  215. `RETRO_SHIFT` enables [`PERMISSIVE_HOLD`-like behaviour](tap_hold.md#permissive-hold) (even if not explicitly enabled) on all mod-taps for which `RETRO_SHIFT` applies.
  216. ## Using Auto Shift Setup
  217. This will enable you to define three keys temporarily to increase, decrease and report your `AUTO_SHIFT_TIMEOUT`.
  218. ### Setup
  219. Map three keys temporarily in your keymap:
  220. |Keycode |Aliases |Description |
  221. |----------------------|---------|--------------------------------------------|
  222. |`QK_AUTO_SHIFT_DOWN` |`AS_DOWN`|Lower the Auto Shift timeout variable (down)|
  223. |`QK_AUTO_SHIFT_UP` |`AS_UP` |Raise the Auto Shift timeout variable (up) |
  224. |`QK_AUTO_SHIFT_REPORT`|`AS_RPT` |Report your current Auto Shift timeout value|
  225. |`QK_AUTO_SHIFT_ON` |`AS_ON` |Turns on the Auto Shift Function |
  226. |`QK_AUTO_SHIFT_OFF` |`AS_OFF` |Turns off the Auto Shift Function |
  227. |`QK_AUTO_SHIFT_TOGGLE`|`AS_TOGG`|Toggles the state of the Auto Shift feature |
  228. Compile and upload your new firmware.
  229. ### Use
  230. It is important to note that during these tests, you should be typing
  231. completely normal and with no intention of shifted keys.
  232. 1. Type multiple sentences of alphabetical letters.
  233. 2. Observe any upper case letters.
  234. 3. If there are none, press the key you have mapped to `AS_DOWN` to decrease
  235. time Auto Shift timeout value and go back to step 1.
  236. 4. If there are some upper case letters, decide if you need to work on tapping
  237. those keys with less down time, or if you need to increase the timeout.
  238. 5. If you decide to increase the timeout, press the key you have mapped to
  239. `AS_UP` and go back to step 1.
  240. 6. Once you are happy with your results, press the key you have mapped to
  241. `AS_RPT`. The keyboard will type by itself the value of your
  242. `AUTO_SHIFT_TIMEOUT`.
  243. 7. Update `AUTO_SHIFT_TIMEOUT` in your `config.h` with the value reported.
  244. 8. Add `AUTO_SHIFT_NO_SETUP` to your `config.h`.
  245. 9. Remove the key bindings `AS_DOWN`, `AS_UP` and `AS_RPT`.
  246. 10. Compile and upload your new firmware.
  247. #### An Example Run
  248. hello world. my name is john doe. i am a computer programmer playing with
  249. keyboards right now.
  250. [PRESS AS_DOWN quite a few times]
  251. heLLo woRLd. mY nAMe is JOHn dOE. i AM A compUTeR proGRaMMER PlAYiNG witH
  252. KEYboArDS RiGHT NOw.
  253. [PRESS AS_UP a few times]
  254. hello world. my name is john Doe. i am a computer programmer playing with
  255. keyboarDs right now.
  256. [PRESS AS_RPT]
  257. 115
  258. The keyboard typed `115` which represents your current `AUTO_SHIFT_TIMEOUT`
  259. value. You are now set! Practice on the *D* key a little bit that showed up
  260. in the testing and you'll be golden.