summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorしぐれ <23041178+ForsakenRei@users.noreply.github.com>2023-03-15 18:55:18 -0400
committerGitHub <noreply@github.com>2023-03-15 16:55:18 -0600
commit012fa6dd4544f25e73b086c377e9f1a57d3d46a9 (patch)
treec9338396fe2b319a5ef7b645fbff126c05b90e7e
parent54dca8cbff3eebcd40d47adea82317ee54260f70 (diff)
[Doc] Add example to keyboard housekeeping and some minor fixes (#19968)
Co-authored-by: jack <0x6a73@protonmail.com>
-rw-r--r--docs/custom_quantum_functions.md58
-rw-r--r--docs/feature_advanced_keycodes.md5
-rw-r--r--docs/feature_key_overrides.md34
-rw-r--r--keyboards/gray_studio/space65r3/readme.md2
4 files changed, 80 insertions, 19 deletions
diff --git a/docs/custom_quantum_functions.md b/docs/custom_quantum_functions.md
index 2917fbad26..5d63f3cfb7 100644
--- a/docs/custom_quantum_functions.md
+++ b/docs/custom_quantum_functions.md
@@ -202,6 +202,62 @@ This function gets called at the end of all QMK processing, before starting the
202 202
203Similar to `matrix_scan_*`, these are called as often as the MCU can handle. To keep your board responsive, it's suggested to do as little as possible during these function calls, potentially throtting their behaviour if you do indeed require implementing something special. 203Similar to `matrix_scan_*`, these are called as often as the MCU can handle. To keep your board responsive, it's suggested to do as little as possible during these function calls, potentially throtting their behaviour if you do indeed require implementing something special.
204 204
205### Example `void housekeeping_task_user(void)` implementation
206
207This example will show you how to use `void housekeeping_task_user(void)` to turn off [RGB Light](feature_rgblight.md). For RGB Matrix, the [builtin](https://docs.qmk.fm/#/feature_rgb_matrix?id=additional-configh-options) `RGB_MATRIX_TIMEOUT` should be used.
208
209First, add the following lines to your keymap's `config.h`:
210
211```c
212#define RGBLIGHT_SLEEP // enable rgblight_suspend() and rgblight_wakeup() in keymap.c
213#define RGBLIGHT_TIMEOUT 900000 // ms to wait until rgblight time out, 900K ms is 15min.
214```
215
216Next, add the following code to your `keymap.c`:
217
218```c
219static uint32_t key_timer; // timer for last keyboard activity, use 32bit value and function to make longer idle time possible
220static void refresh_rgb(void); // refreshes the activity timer and RGB, invoke whenever any activity happens
221static void check_rgb_timeout(void); // checks if enough time has passed for RGB to timeout
222bool is_rgb_timeout = false; // store if RGB has timed out or not in a boolean
223
224void refresh_rgb(void) {
225 key_timer = timer_read32(); // store time of last refresh
226 if (is_rgb_timeout)
227 {
228 is_rgb_timeout = false;
229 rgblight_wakeup();
230 }
231}
232void check_rgb_timeout(void) {
233 if (!is_rgb_timeout && timer_elapsed32(key_timer) > RGBLIGHT_TIMEOUT) // check if RGB has already timeout and if enough time has passed
234 {
235 rgblight_suspend();
236 is_rgb_timeout = true;
237 }
238}
239/* Then, call the above functions from QMK's built in post processing functions like so */
240/* Runs at the end of each scan loop, check if RGB timeout has occured or not */
241void housekeeping_task_user(void) {
242#ifdef RGBLIGHT_TIMEOUT
243 check_rgb_timeout();
244#endif
245}
246/* Runs after each key press, check if activity occurred */
247void post_process_record_user(uint16_t keycode, keyrecord_t *record) {
248#ifdef RGBLIGHT_TIMEOUT
249 if (record->event.pressed)
250 refresh_rgb();
251#endif
252}
253/* Runs after each encoder tick, check if activity occurred */
254void post_encoder_update_user(uint8_t index, bool clockwise) {
255#ifdef RGBLIGHT_TIMEOUT
256 refresh_rgb();
257#endif
258}
259```
260
205# Keyboard Idling/Wake Code 261# Keyboard Idling/Wake Code
206 262
207If the board supports it, it can be "idled", by stopping a number of functions. A good example of this is RGB lights or backlights. This can save on power consumption, or may be better behavior for your keyboard. 263If the board supports it, it can be "idled", by stopping a number of functions. A good example of this is RGB lights or backlights. This can save on power consumption, or may be better behavior for your keyboard.
@@ -209,7 +265,7 @@ If the board supports it, it can be "idled", by stopping a number of functions.
209This is controlled by two functions: `suspend_power_down_*` and `suspend_wakeup_init_*`, which are called when the system board is idled and when it wakes up, respectively. 265This is controlled by two functions: `suspend_power_down_*` and `suspend_wakeup_init_*`, which are called when the system board is idled and when it wakes up, respectively.
210 266
211 267
212### Example suspend_power_down_user() and suspend_wakeup_init_user() Implementation 268### Example `suspend_power_down_user()` and `suspend_wakeup_init_user()` Implementation
213 269
214 270
215```c 271```c
diff --git a/docs/feature_advanced_keycodes.md b/docs/feature_advanced_keycodes.md
index b04721b23a..90f06e405a 100644
--- a/docs/feature_advanced_keycodes.md
+++ b/docs/feature_advanced_keycodes.md
@@ -160,6 +160,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
160 return true; 160 return true;
161}; 161};
162``` 162```
163Alternatively, this can be done with [Key Overrides](feature_key_overrides?id=simple-example).
163 164
164# Advanced topics :id=advanced-topics 165# Advanced topics :id=advanced-topics
165 166
@@ -180,3 +181,7 @@ This page used to encompass a large set of features. We have moved many sections
180## Tap-Hold Configuration Options :id=tap-hold-configuration-options 181## Tap-Hold Configuration Options :id=tap-hold-configuration-options
181 182
182* [Tap-Hold Configuration Options](tap_hold.md) 183* [Tap-Hold Configuration Options](tap_hold.md)
184
185## Key Overrides :id=key-overrides
186
187* [Key Overrides](feature_key_overrides.md) \ No newline at end of file
diff --git a/docs/feature_key_overrides.md b/docs/feature_key_overrides.md
index 36fd383cd4..608eb001e4 100644
--- a/docs/feature_key_overrides.md
+++ b/docs/feature_key_overrides.md
@@ -1,4 +1,4 @@
1# Key Overrides 1# Key Overrides :id=key-overrides
2 2
3Key overrides allow you to override modifier-key combinations to send a different modifier-key combination or perform completely custom actions. Don't want `shift` + `1` to type `!` on your computer? Use a key override to make your keyboard type something different when you press `shift` + `1`. The general behavior is like this: If `modifiers w` + `key x` are pressed, replace these keys with `modifiers y` + `key z` in the keyboard report. 3Key overrides allow you to override modifier-key combinations to send a different modifier-key combination or perform completely custom actions. Don't want `shift` + `1` to type `!` on your computer? Use a key override to make your keyboard type something different when you press `shift` + `1`. The general behavior is like this: If `modifiers w` + `key x` are pressed, replace these keys with `modifiers y` + `key z` in the keyboard report.
4 4
@@ -10,13 +10,13 @@ You can use key overrides in a similar way to momentary layer/fn keys to activat
10- Create custom shortcuts or change existing ones: E.g. Send `ctrl`+`shift`+`z` when `ctrl`+`y` is pressed. 10- Create custom shortcuts or change existing ones: E.g. Send `ctrl`+`shift`+`z` when `ctrl`+`y` is pressed.
11- Run custom code when `ctrl` + `alt` + `esc` is pressed. 11- Run custom code when `ctrl` + `alt` + `esc` is pressed.
12 12
13## Setup 13## Setup :id=setup
14 14
15To enable this feature, you need to add `KEY_OVERRIDE_ENABLE = yes` to your `rules.mk`. 15To enable this feature, you need to add `KEY_OVERRIDE_ENABLE = yes` to your `rules.mk`.
16 16
17Then, in your `keymap.c` file, you'll need to define the array `key_overrides`, which defines all key overrides to be used. Each override is a value of type `key_override_t`. The array `key_overrides` is `NULL`-terminated and contains pointers to `key_override_t` values (`const key_override_t **`). 17Then, in your `keymap.c` file, you'll need to define the array `key_overrides`, which defines all key overrides to be used. Each override is a value of type `key_override_t`. The array `key_overrides` is `NULL`-terminated and contains pointers to `key_override_t` values (`const key_override_t **`).
18 18
19## Creating Key Overrides 19## Creating Key Overrides :id=creating-key-overrides
20 20
21The `key_override_t` struct has many options that allow you to precisely tune your overrides. The full reference is shown below. Instead of manually creating a `key_override_t` value, it is recommended to use these dedicated initializers: 21The `key_override_t` struct has many options that allow you to precisely tune your overrides. The full reference is shown below. Instead of manually creating a `key_override_t` value, it is recommended to use these dedicated initializers:
22 22
@@ -34,7 +34,7 @@ Additionally takes a bitmask `options` that specifies additional options. See `k
34 34
35For more customization possibilities, you may directly create a `key_override_t`, which allows you to customize even more behavior. Read further below for details and examples. 35For more customization possibilities, you may directly create a `key_override_t`, which allows you to customize even more behavior. Read further below for details and examples.
36 36
37## Simple Example 37## Simple Example :id=simple-example
38 38
39This shows how the mentioned example of sending `delete` when `shift` + `backspace` are pressed is realized: 39This shows how the mentioned example of sending `delete` when `shift` + `backspace` are pressed is realized:
40 40
@@ -48,9 +48,9 @@ const key_override_t **key_overrides = (const key_override_t *[]){
48}; 48};
49``` 49```
50 50
51## Intermediate Difficulty Examples 51## Intermediate Difficulty Examples :id=intermediate-difficulty-examples
52 52
53### Media Controls & Screen Brightness 53### Media Controls & Screen Brightness :id=media-controls-amp-screen-brightness
54 54
55In this example a single key is configured to control media, volume and screen brightness by using key overrides. 55In this example a single key is configured to control media, volume and screen brightness by using key overrides.
56 56
@@ -102,7 +102,7 @@ const key_override_t **key_overrides = (const key_override_t *[]){
102}; 102};
103``` 103```
104 104
105### Flexible macOS-friendly Grave Escape 105### Flexible macOS-friendly Grave Escape :id=flexible-macos-friendly-grave-escape
106The [Grave Escape feature](feature_grave_esc.md) is limited in its configurability and has [bugs when used on macOS](feature_grave_esc.md#caveats). Key overrides can be used to achieve a similar functionality as Grave Escape, but with more customization and without bugs on macOS. 106The [Grave Escape feature](feature_grave_esc.md) is limited in its configurability and has [bugs when used on macOS](feature_grave_esc.md#caveats). Key overrides can be used to achieve a similar functionality as Grave Escape, but with more customization and without bugs on macOS.
107 107
108```c 108```c
@@ -121,8 +121,8 @@ const key_override_t **key_overrides = (const key_override_t *[]){
121 121
122In addition to not encountering unexpected bugs on macOS, you can also change the behavior as you wish. Instead setting `GUI` + `ESC` = `` ` `` you may change it to an arbitrary other modifier, for example `Ctrl` + `ESC` = `` ` ``. 122In addition to not encountering unexpected bugs on macOS, you can also change the behavior as you wish. Instead setting `GUI` + `ESC` = `` ` `` you may change it to an arbitrary other modifier, for example `Ctrl` + `ESC` = `` ` ``.
123 123
124## Advanced Examples 124## Advanced Examples :id=advanced-examples
125### Modifiers as Layer Keys 125### Modifiers as Layer Keys :id=modifiers-as-layer-keys
126 126
127Do you really need a dedicated key to toggle your fn layer? With key overrides, perhaps not. This example shows how you can configure to use `rGUI` + `rAlt` (right GUI and right alt) to access a momentary layer like an fn layer. With this you completely eliminate the need to use a dedicated layer key. Of course the choice of modifier keys can be changed as needed, `rGUI` + `rAlt` is just an example here. 127Do you really need a dedicated key to toggle your fn layer? With key overrides, perhaps not. This example shows how you can configure to use `rGUI` + `rAlt` (right GUI and right alt) to access a momentary layer like an fn layer. With this you completely eliminate the need to use a dedicated layer key. Of course the choice of modifier keys can be changed as needed, `rGUI` + `rAlt` is just an example here.
128 128
@@ -150,7 +150,7 @@ const key_override_t fn_override = {.trigger_mods = MOD_BIT(KC_RGUI) |
150 .enabled = NULL}; 150 .enabled = NULL};
151``` 151```
152 152
153## Keycodes 153## Keycodes :id=keycodes
154 154
155|Keycode |Aliases |Description | 155|Keycode |Aliases |Description |
156|------------------------|---------|----------------------| 156|------------------------|---------|----------------------|
@@ -158,7 +158,7 @@ const key_override_t fn_override = {.trigger_mods = MOD_BIT(KC_RGUI) |
158|`QK_KEY_OVERRIDE_ON` |`KO_ON` |Turn on key overrides | 158|`QK_KEY_OVERRIDE_ON` |`KO_ON` |Turn on key overrides |
159|`QK_KEY_OVERRIDE_OFF` |`KO_OFF` |Turn off key overrides| 159|`QK_KEY_OVERRIDE_OFF` |`KO_OFF` |Turn off key overrides|
160 160
161## Reference for `key_override_t` 161## Reference for `key_override_t` :id=reference-for-key_override_t
162 162
163Advanced users may need more customization than what is offered by the simple `ko_make` initializers. For this, directly create a `key_override_t` value and set all members. Below is a reference for all members of `key_override_t`. 163Advanced users may need more customization than what is offered by the simple `ko_make` initializers. For this, directly create a `key_override_t` value and set all members. Below is a reference for all members of `key_override_t`.
164 164
@@ -175,7 +175,7 @@ Advanced users may need more customization than what is offered by the simple `k
175| `void *context` | A context that will be passed to the custom action function. | 175| `void *context` | A context that will be passed to the custom action function. |
176| `bool *enabled` | If this points to false this override will not be used. Set to NULL to always have this override enabled. | 176| `bool *enabled` | If this points to false this override will not be used. Set to NULL to always have this override enabled. |
177 177
178### Reference for `ko_option_t` 178## Reference for `ko_option_t` :id=reference-for-ko_option_t
179 179
180Bitfield with various options controlling the behavior of a key override. 180Bitfield with various options controlling the behavior of a key override.
181 181
@@ -189,11 +189,11 @@ Bitfield with various options controlling the behavior of a key override.
189| `ko_option_no_reregister_trigger` | If set, the trigger key will never be registered again after the override is deactivated. | 189| `ko_option_no_reregister_trigger` | If set, the trigger key will never be registered again after the override is deactivated. |
190| `ko_options_default` | The default options used by the `ko_make_xxx` functions | 190| `ko_options_default` | The default options used by the `ko_make_xxx` functions |
191 191
192## For Advanced Users: Inner Workings 192## For Advanced Users: Inner Workings :id=for-advanced-users-inner-workings
193 193
194This section explains how a key override works in detail, explaining where each member of `key_override_t` comes into play. Understanding this is essential to be able to take full advantage of all the options offered by key overrides. 194This section explains how a key override works in detail, explaining where each member of `key_override_t` comes into play. Understanding this is essential to be able to take full advantage of all the options offered by key overrides.
195 195
196#### Activation 196#### Activation :id=activation
197 197
198When the necessary keys are pressed (`trigger_mods` + `trigger`), the override is 'activated' and the replacement key is registered in the keyboard report (`replacement`), while the `trigger` key is removed from the keyboard report. The trigger modifiers may also be removed from the keyboard report upon activation of an override (`suppressed_mods`). The override will not activate if any of the `negative_modifiers` are pressed. 198When the necessary keys are pressed (`trigger_mods` + `trigger`), the override is 'activated' and the replacement key is registered in the keyboard report (`replacement`), while the `trigger` key is removed from the keyboard report. The trigger modifiers may also be removed from the keyboard report upon activation of an override (`suppressed_mods`). The override will not activate if any of the `negative_modifiers` are pressed.
199 199
@@ -207,11 +207,11 @@ Use the `option` member to customize which of these events are allowed to activa
207 207
208In any case, a key override can only activate if the `trigger` key is the _last_ non-modifier key that was pressed down. This emulates the behavior of how standard OSes (macOS, Windows, Linux) handle normal key input (to understand: Hold down `a`, then also hold down `b`, then hold down `shift`; `B` will be typed but not `A`). 208In any case, a key override can only activate if the `trigger` key is the _last_ non-modifier key that was pressed down. This emulates the behavior of how standard OSes (macOS, Windows, Linux) handle normal key input (to understand: Hold down `a`, then also hold down `b`, then hold down `shift`; `B` will be typed but not `A`).
209 209
210#### Deactivation 210#### Deactivation :id=deactivation
211 211
212An override is 'deactivated' when one of the trigger keys (`trigger_mods`, `trigger`) is lifted, another non-modifier key is pressed down, or one of the `negative_modifiers` is pressed down. When an override deactivates, the `replacement` key is removed from the keyboard report, while the `suppressed_mods` that are still held down are re-added to the keyboard report. By default, the `trigger` key is re-added to the keyboard report if it is still held down and no other non-modifier key has been pressed since. This again emulates the behavior of how standard OSes handle normal key input (To understand: hold down `a`, then also hold down `b`, then also `shift`, then release `b`; `A` will not be typed even though you are holding the `a` and `shift` keys). Use the `option` field `ko_option_no_reregister_trigger` to prevent re-registering the trigger key in all cases. 212An override is 'deactivated' when one of the trigger keys (`trigger_mods`, `trigger`) is lifted, another non-modifier key is pressed down, or one of the `negative_modifiers` is pressed down. When an override deactivates, the `replacement` key is removed from the keyboard report, while the `suppressed_mods` that are still held down are re-added to the keyboard report. By default, the `trigger` key is re-added to the keyboard report if it is still held down and no other non-modifier key has been pressed since. This again emulates the behavior of how standard OSes handle normal key input (To understand: hold down `a`, then also hold down `b`, then also `shift`, then release `b`; `A` will not be typed even though you are holding the `a` and `shift` keys). Use the `option` field `ko_option_no_reregister_trigger` to prevent re-registering the trigger key in all cases.
213 213
214#### Key Repeat Delay 214#### Key Repeat Delay :id=key-repeat-delay
215 215
216A third way in which standard OS-handling of modifier-key input is emulated in key overrides is with a ['key repeat delay'](https://www.dummies.com/computers/pcs/set-your-keyboards-repeat-delay-and-repeat-rate/). To explain what this is, let's look at how normal keyboard input is handled by mainstream OSes again: If you hold down `a`, followed by `shift`, you will see the letter `a` is first typed, then for a short moment nothing is typed and then repeating `A`s are typed. Take note that, although shift is pressed down just after `a` is pressed, it takes a moment until `A` is typed. This is caused by the aforementioned key repeat delay, and it is a feature that prevents unwanted repeated characters from being typed. 216A third way in which standard OS-handling of modifier-key input is emulated in key overrides is with a ['key repeat delay'](https://www.dummies.com/computers/pcs/set-your-keyboards-repeat-delay-and-repeat-rate/). To explain what this is, let's look at how normal keyboard input is handled by mainstream OSes again: If you hold down `a`, followed by `shift`, you will see the letter `a` is first typed, then for a short moment nothing is typed and then repeating `A`s are typed. Take note that, although shift is pressed down just after `a` is pressed, it takes a moment until `A` is typed. This is caused by the aforementioned key repeat delay, and it is a feature that prevents unwanted repeated characters from being typed.
217 217
@@ -222,6 +222,6 @@ This applies equally to releasing a modifier: When you hold `shift`, then press
222The duration of the key repeat delay is controlled with the `KEY_OVERRIDE_REPEAT_DELAY` macro. Define this value in your `config.h` file to change it. It is 500ms by default. 222The duration of the key repeat delay is controlled with the `KEY_OVERRIDE_REPEAT_DELAY` macro. Define this value in your `config.h` file to change it. It is 500ms by default.
223 223
224 224
225## Difference to Combos 225## Difference to Combos :id=difference-to-combos
226 226
227Note that key overrides are very different from [combos](https://docs.qmk.fm/#/feature_combo). Combos require that you press down several keys almost _at the same time_ and can work with any combination of non-modifier keys. Key overrides work like keyboard shortcuts (e.g. `ctrl` + `z`): They take combinations of _multiple_ modifiers and _one_ non-modifier key to then perform some custom action. Key overrides are implemented with much care to behave just like normal keyboard shortcuts would in regards to the order of pressed keys, timing, and interacton with other pressed keys. There are a number of optional settings that can be used to really fine-tune the behavior of each key override as well. Using key overrides also does not delay key input for regular key presses, which inherently happens in combos and may be undesirable. 227Note that key overrides are very different from [combos](https://docs.qmk.fm/#/feature_combo). Combos require that you press down several keys almost _at the same time_ and can work with any combination of non-modifier keys. Key overrides work like keyboard shortcuts (e.g. `ctrl` + `z`): They take combinations of _multiple_ modifiers and _one_ non-modifier key to then perform some custom action. Key overrides are implemented with much care to behave just like normal keyboard shortcuts would in regards to the order of pressed keys, timing, and interacton with other pressed keys. There are a number of optional settings that can be used to really fine-tune the behavior of each key override as well. Using key overrides also does not delay key input for regular key presses, which inherently happens in combos and may be undesirable.
diff --git a/keyboards/gray_studio/space65r3/readme.md b/keyboards/gray_studio/space65r3/readme.md
index 4f89d3851a..2de127bd7a 100644
--- a/keyboards/gray_studio/space65r3/readme.md
+++ b/keyboards/gray_studio/space65r3/readme.md
@@ -1,4 +1,4 @@
1# Gray Studio 65 R3 1# Gray Studio Space65 R3
2 2
3A 65% keyboard by Graystudio. PCB designed and manufactured by DEMO Studio. 3A 65% keyboard by Graystudio. PCB designed and manufactured by DEMO Studio.
4 4