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.

392 lines
14 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 the KC_TAB.
  100. ### NO_AUTO_SHIFT_TAB (simple define)
  101. Do not Auto Shift KC_TAB but leave Auto Shift enabled for the other special
  102. characters.
  103. ### NO_AUTO_SHIFT_SYMBOLS (simple define)
  104. Do not Auto Shift symbol keys, which include -\_, =+, [{, ]}, ;:, '", ,<, .>,
  105. and /?.
  106. ### NO_AUTO_SHIFT_NUMERIC (simple define)
  107. Do not Auto Shift numeric keys, zero through nine.
  108. ### NO_AUTO_SHIFT_ALPHA (simple define)
  109. Do not Auto Shift alpha characters, which include A through Z.
  110. ### AUTO_SHIFT_ENTER (simple define)
  111. Auto Shift the enter key.
  112. ### Auto Shift Per Key
  113. There are functions that allows you to determine which keys should be autoshifted, much like the tap-hold keys.
  114. The first of these, used to simply add a key to Auto Shift, is `get_custom_auto_shifted_key`:
  115. ```c
  116. bool get_custom_auto_shifted_key(uint16_t keycode, keyrecord_t *record) {
  117. switch(keycode) {
  118. case KC_DOT:
  119. return true;
  120. default:
  121. return false;
  122. }
  123. }
  124. ```
  125. For more granular control, there is `get_auto_shifted_key`. The default function looks like this:
  126. ```c
  127. bool get_auto_shifted_key(uint16_t keycode, keyrecord_t *record) {
  128. switch (keycode) {
  129. # ifndef NO_AUTO_SHIFT_ALPHA
  130. case AUTO_SHIFT_ALPHA:
  131. # endif
  132. # ifndef NO_AUTO_SHIFT_NUMERIC
  133. case AUTO_SHIFT_NUMERIC:
  134. # endif
  135. # ifndef NO_AUTO_SHIFT_SPECIAL
  136. # ifndef NO_AUTO_SHIFT_TAB
  137. case KC_TAB:
  138. # endif
  139. # ifndef NO_AUTO_SHIFT_SYMBOLS
  140. case AUTO_SHIFT_SYMBOLS:
  141. # endif
  142. # endif
  143. # ifdef AUTO_SHIFT_ENTER
  144. case KC_ENT:
  145. # endif
  146. return true;
  147. }
  148. return get_custom_auto_shifted_key(keycode, record);
  149. }
  150. ```
  151. This functionality is enabled by default, and does not need a define.
  152. ### AUTO_SHIFT_REPEAT (simple define)
  153. Enables keyrepeat.
  154. ### AUTO_SHIFT_NO_AUTO_REPEAT (simple define)
  155. Disables automatically keyrepeating when `AUTO_SHIFT_TIMEOUT` is exceeded.
  156. ### AUTO_SHIFT_ALPHA (predefined key group)
  157. A predefined group of keys representing A through Z.
  158. ### AUTO_SHIFT_NUMERIC (predefined key group)
  159. A predefined group of keys representing 0 through 9. Note, these are defined as
  160. 1 through 0 since that is the order they normally appear in.
  161. ### AUTO_SHIFT_SYMBOLS (predefined key group)
  162. A predefined group of keys representing symbolic characters which include -\_, =+, [{, ]}, ;:, '", ,<, .>,
  163. and /?.
  164. ### AUTO_SHIFT_SPECIAL (predefined key group)
  165. A predefined group of keys that combines AUTO_SHIFT_SYMBOLS and KC_TAB.
  166. ## Custom Shifted Values
  167. Especially on small keyboards, the default shifted value for many keys is not
  168. optimal. To provide more customizability, there are two user-definable
  169. functions, `autoshift_press/release_user`. These register or unregister the
  170. correct value for the passed key. Below is an example adding period to Auto
  171. Shift and making its shifted value exclamation point. Make sure to use weak
  172. mods - setting real would make any keys following it use their shifted values
  173. as if you were holding the key. Clearing of modifiers is handled by Auto Shift,
  174. and the OS-sent shift value if keyrepeating multiple keys is always that of
  175. the last key pressed (whether or not it's an Auto Shift key).
  176. You can also have non-shifted keys for the shifted values (or even no shifted
  177. value), just don't set a shift modifier!
  178. ```c
  179. bool get_custom_auto_shifted_key(uint16_t keycode, keyrecord_t *record) {
  180. switch(keycode) {
  181. case KC_DOT:
  182. return true;
  183. default:
  184. return false;
  185. }
  186. }
  187. void autoshift_press_user(uint16_t keycode, bool shifted, keyrecord_t *record) {
  188. switch(keycode) {
  189. case KC_DOT:
  190. register_code16((!shifted) ? KC_DOT : KC_EXLM);
  191. break;
  192. default:
  193. if (shifted) {
  194. add_weak_mods(MOD_BIT(KC_LSFT));
  195. }
  196. // & 0xFF gets the Tap key for Tap Holds, required when using Retro Shift
  197. register_code16((IS_RETRO(keycode)) ? keycode & 0xFF : keycode);
  198. }
  199. }
  200. void autoshift_release_user(uint16_t keycode, bool shifted, keyrecord_t *record) {
  201. switch(keycode) {
  202. case KC_DOT:
  203. unregister_code16((!shifted) ? KC_DOT : KC_EXLM);
  204. break;
  205. default:
  206. // & 0xFF gets the Tap key for Tap Holds, required when using Retro Shift
  207. // The IS_RETRO check isn't really necessary here, always using
  208. // keycode & 0xFF would be fine.
  209. unregister_code16((IS_RETRO(keycode)) ? keycode & 0xFF : keycode);
  210. }
  211. }
  212. ```
  213. ## Retro Shift
  214. Holding and releasing a Tap Hold key without pressing another key will ordinarily
  215. result in only the hold. With `retro shift` enabled this action will instead
  216. produce a shifted version of the tap keycode on release.
  217. It does not require [Retro Tapping](tap_hold.md#retro-tapping) to be enabled, and
  218. if both are enabled the state of `retro tapping` will only apply if the tap keycode
  219. is not matched by Auto Shift. `RETRO_TAPPING_PER_KEY` and its corresponding
  220. function, however, are checked before `retro shift` is applied.
  221. To enable `retro shift`, add the following to your `config.h`:
  222. ```c
  223. #define RETRO_SHIFT
  224. ```
  225. If `RETRO_SHIFT` is defined to a value, hold times greater than that value will
  226. not produce a tap on release for Mod Taps, and instead triggers the hold action.
  227. This enables modifiers to be held for combining with mouse clicks without
  228. generating taps on release. For example:
  229. ```c
  230. #define RETRO_SHIFT 500
  231. ```
  232. Without a value set, holds of any length without an interrupting key will produce the shifted value.
  233. This value (if set) must be greater than one's `TAPPING_TERM`, as the key press
  234. must be designated as a 'hold' by `process_tapping` before we send the modifier.
  235. [Per-key tapping terms](tap_hold.md#tapping-term) can be used as a workaround.
  236. There is no such limitation in regards to `AUTO_SHIFT_TIMEOUT` for normal keys.
  237. **Note:** Tap Holds must be added to Auto Shift, see [here.](feature_auto_shift.md#auto-shift-per-key)
  238. `IS_RETRO` may be helpful if one wants all Tap Holds retro shifted.
  239. ### Retro Shift and Tap Hold Configurations
  240. Tap Hold Configurations work a little differently when using Retro Shift.
  241. Referencing `TAPPING_TERM` makes little sense, as holding longer would result in
  242. shifting one of the keys.
  243. `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.
  244. ## Using Auto Shift Setup
  245. This will enable you to define three keys temporarily to increase, decrease and report your `AUTO_SHIFT_TIMEOUT`.
  246. ### Setup
  247. Map three keys temporarily in your keymap:
  248. |Keycode |Aliases |Description |
  249. |----------------------|---------|--------------------------------------------|
  250. |`QK_AUTO_SHIFT_DOWN` |`AS_DOWN`|Lower the Auto Shift timeout variable (down)|
  251. |`QK_AUTO_SHIFT_UP` |`AS_UP` |Raise the Auto Shift timeout variable (up) |
  252. |`QK_AUTO_SHIFT_REPORT`|`AS_RPT` |Report your current Auto Shift timeout value|
  253. |`QK_AUTO_SHIFT_ON` |`AS_ON` |Turns on the Auto Shift Function |
  254. |`QK_AUTO_SHIFT_OFF` |`AS_OFF` |Turns off the Auto Shift Function |
  255. |`QK_AUTO_SHIFT_TOGGLE`|`AS_TOGG`|Toggles the state of the Auto Shift feature |
  256. Compile and upload your new firmware.
  257. ### Use
  258. It is important to note that during these tests, you should be typing
  259. completely normal and with no intention of shifted keys.
  260. 1. Type multiple sentences of alphabetical letters.
  261. 2. Observe any upper case letters.
  262. 3. If there are none, press the key you have mapped to `AS_DOWN` to decrease
  263. time Auto Shift timeout value and go back to step 1.
  264. 4. If there are some upper case letters, decide if you need to work on tapping
  265. those keys with less down time, or if you need to increase the timeout.
  266. 5. If you decide to increase the timeout, press the key you have mapped to
  267. `AS_UP` and go back to step 1.
  268. 6. Once you are happy with your results, press the key you have mapped to
  269. `AS_RPT`. The keyboard will type by itself the value of your
  270. `AUTO_SHIFT_TIMEOUT`.
  271. 7. Update `AUTO_SHIFT_TIMEOUT` in your `config.h` with the value reported.
  272. 8. Add `AUTO_SHIFT_NO_SETUP` to your `config.h`.
  273. 9. Remove the key bindings `AS_DOWN`, `AS_UP` and `AS_RPT`.
  274. 10. Compile and upload your new firmware.
  275. #### An Example Run
  276. hello world. my name is john doe. i am a computer programmer playing with
  277. keyboards right now.
  278. [PRESS AS_DOWN quite a few times]
  279. heLLo woRLd. mY nAMe is JOHn dOE. i AM A compUTeR proGRaMMER PlAYiNG witH
  280. KEYboArDS RiGHT NOw.
  281. [PRESS AS_UP a few times]
  282. hello world. my name is john Doe. i am a computer programmer playing with
  283. keyboarDs right now.
  284. [PRESS AS_RPT]
  285. 115
  286. The keyboard typed `115` which represents your current `AUTO_SHIFT_TIMEOUT`
  287. value. You are now set! Practice on the *D* key a little bit that showed up
  288. in the testing and you'll be golden.