aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2018-12-20 08:58:12 -0800
committerMechMerlin <30334081+mechmerlin@users.noreply.github.com>2018-12-20 08:58:12 -0800
commit639585314863912480c9967fc38bb2d9418a34ab (patch)
treed62dd53e99ba77896309a0736c1e34b4816eaba2
parent1586548b4f45f76d9cd05be4ee9588b3d4b3860e (diff)
downloadqmk_firmware-639585314863912480c9967fc38bb2d9418a34ab.tar.gz
qmk_firmware-639585314863912480c9967fc38bb2d9418a34ab.zip
Docs: Add additional clarification to Leader Key documention (#4660)
* Add clarification for Leader Timeout * Add additional documentatin to config_options.md * Add leader_start() and leader_end() documentation * Add Examples * Clarify timout * Remove customization * Improve docs based on feedback * Better clarification of features * Fix example * Spelling/grammar issue * Spelling and clarification
-rw-r--r--docs/config_options.md1
-rw-r--r--docs/feature_leader_key.md82
2 files changed, 76 insertions, 7 deletions
diff --git a/docs/config_options.md b/docs/config_options.md
index fb1655e9a..879761a40 100644
--- a/docs/config_options.md
+++ b/docs/config_options.md
@@ -143,6 +143,7 @@ If you define these options you will enable the associated feature, which may in
143 * Breaks any Tap Toggle functionality (`TT` or the One Shot Tap Toggle) 143 * Breaks any Tap Toggle functionality (`TT` or the One Shot Tap Toggle)
144* `#define LEADER_TIMEOUT 300` 144* `#define LEADER_TIMEOUT 300`
145 * how long before the leader key times out 145 * how long before the leader key times out
146 * If you're having issues finishing the sequence before it times out, you may need to increase the timeout setting. Or you may want to enable the `LEADER_PER_KEY_TIMING` option, which resets the timeout after each key is tapped.
146* `#define LEADER_PER_KEY_TIMING` 147* `#define LEADER_PER_KEY_TIMING`
147 * sets the timer for leader key chords to run on each key press rather than overall 148 * sets the timer for leader key chords to run on each key press rather than overall
148* `#define ONESHOT_TIMEOUT 300` 149* `#define ONESHOT_TIMEOUT 300`
diff --git a/docs/feature_leader_key.md b/docs/feature_leader_key.md
index 9b49e0fd9..168a1fc1c 100644
--- a/docs/feature_leader_key.md
+++ b/docs/feature_leader_key.md
@@ -5,10 +5,11 @@ If you've ever used Vim, you know what a Leader key is. If not, you're about to
5That's what `KC_LEAD` does. Here's an example: 5That's what `KC_LEAD` does. Here's an example:
6 6
71. Pick a key on your keyboard you want to use as the Leader key. Assign it the keycode `KC_LEAD`. This key would be dedicated just for this -- it's a single action key, can't be used for anything else. 71. Pick a key on your keyboard you want to use as the Leader key. Assign it the keycode `KC_LEAD`. This key would be dedicated just for this -- it's a single action key, can't be used for anything else.
82. Include the line `#define LEADER_TIMEOUT 300` in your config.h. The 300 there is 300ms -- that's how long you have for the sequence of keys following the leader. You can tweak this value for comfort, of course. 82. Include the line `#define LEADER_TIMEOUT 300` in your `config.h`. This sets the timeout for the `KC_LEAD` key. Specifically, when you press the `KC_LEAD` key, you only have a certain amount of time to complete the Leader Key sequence. The `300` here sets that to 300ms, and you can increase this value to give you more time to hit the sequence. But any keys pressed during this timeout are intercepted and not sent, so you may want to keep this value low. .
93. Within your `matrix_scan_user` function, do something like this: 9 * By default, this timeout is how long after pressing `KC_LEAD` to complete your entire sequence. This may be very low for some people. So you may want to increase this timeout. Optionally, you may want to enable the `LEADER_PER_KEY_TIMING` option, which resets the timeout after each key is tapped. This allows you to maintain a low value here, but still be able to use the longer sequences. To enable this option, add `#define LEADER_PER_KEY_TIMING` to your `config.h`.
103. Within your `matrix_scan_user` function, add something like this:
10 11
11``` 12```c
12LEADER_EXTERNS(); 13LEADER_EXTERNS();
13 14
14void matrix_scan_user(void) { 15void matrix_scan_user(void) {
@@ -44,7 +45,7 @@ Each of these accepts one or more keycodes as arguments. This is an important po
44 45
45To add support for Leader Key you simply need to add a single line to your keymap's `rules.mk`: 46To add support for Leader Key you simply need to add a single line to your keymap's `rules.mk`:
46 47
47``` 48```make
48LEADER_ENABLE = yes 49LEADER_ENABLE = yes
49``` 50```
50 51
@@ -53,20 +54,87 @@ LEADER_ENABLE = yes
53Rather than relying on an incredibly high timeout for long leader key strings or those of us without 200wpm typing skills, we can enable per key timing to ensure that each key pressed provides us with more time to finish our stroke. This is incredibly helpful with leader key emulation of tap dance (read: multiple taps of the same key like C, C, C). 54Rather than relying on an incredibly high timeout for long leader key strings or those of us without 200wpm typing skills, we can enable per key timing to ensure that each key pressed provides us with more time to finish our stroke. This is incredibly helpful with leader key emulation of tap dance (read: multiple taps of the same key like C, C, C).
54 55
55In order to enable this, place this in your `config.h`: 56In order to enable this, place this in your `config.h`:
56``` 57```c
57#define LEADER_PER_KEY_TIMING 58#define LEADER_PER_KEY_TIMING
58``` 59```
59 60
60After this, it's recommended that you lower your `LEADER_TIMEOUT` to something less that 300ms. 61After this, it's recommended that you lower your `LEADER_TIMEOUT` to something less that 300ms.
61 62
62``` 63```c
63#define LEADER_TIMEOUT 250 64#define LEADER_TIMEOUT 250
64``` 65```
65 66
66Now, something like this won't seem impossible to do without a 1000MS leader key timeout: 67Now, something like this won't seem impossible to do without a 1000MS leader key timeout:
67 68
68``` 69```c
69SEQ_THREE_KEYS(KC_C, KC_C, KC_C) { 70SEQ_THREE_KEYS(KC_C, KC_C, KC_C) {
70 SEND_STRING("Per key timing is great!!!"); 71 SEND_STRING("Per key timing is great!!!");
71} 72}
72``` 73```
74
75## Customization
76
77The Leader Key feature has some additional customization to how the Leader Key feature works. It has two functions that can be called at certain parts of the process. Namely `leader_start()` and `leader_end()`.
78
79The `leader_start()` function is called when you tap the `KC_LEAD` key, and the `leader_end()` function is called when either the leader sequence is completed, or the leader timeout is hit.
80
81You can add these functions to your code (`keymap.c` usually) to add feedback to the Leader sequences (such as beeping or playing music).
82
83```c
84void leader_start(void) {
85 // sequence started
86}
87
88void leader_end(void) {
89 // sequence ended (no success/failuer detection)
90}
91```
92
93### Example
94
95This example will play the Mario "One Up" sound when you hit `KC_LEAD` to start the Leader Sequence, and will play "All Star" if it completes successfully or "Rick Roll" you if it fails.
96
97```c
98bool did_leader_succeed;
99#ifdef AUDIO_ENABLE
100float leader_start[][2] = SONG(ONE_UP_SOUND );
101float leader_succeed[][2] = SONG(ALL_STAR);
102float leader_fail[][2] = SONG(RICK_ROLL);
103#endif
104LEADER_EXTERNS();
105
106void matrix_scan_user(void) {
107 LEADER_DICTIONARY() {
108 did_leader_succeed = leading = false;
109
110 SEQ_ONE_KEY(KC_E) {
111 // Anything you can do in a macro.
112 SEND_STRING(SS_LCTRL(SS_LSFT("t")));
113 did_leader_succeed = true;
114 } else
115 SEQ_TWO_KEYS(KC_E, KC_D) {
116 SEND_STRING(SS_LGUI("r")"cmd"SS_TAP(KC_ENTER)SS_LCTRL("c"));
117 did_leader_succeed = true;
118 }
119 leader_end();
120 }
121}
122
123void leader_start(void) {
124#ifdef AUDIO_ENABLE
125 PLAY_SONG(leader_start);
126#endif
127}
128
129void leader_end(void) {
130 if (did_leader_succeed) {
131#ifdef AUDIO_ENABLE
132 PLAY_SONG(leader_succeed);
133#endif
134 } else {
135#ifdef AUDIO_ENABLE
136 PLAY_SONG(leader_fail);
137#endif
138 }
139}
140```