aboutsummaryrefslogtreecommitdiff
path: root/docs/one_shot_keys.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/one_shot_keys.md')
-rw-r--r--docs/one_shot_keys.md102
1 files changed, 102 insertions, 0 deletions
diff --git a/docs/one_shot_keys.md b/docs/one_shot_keys.md
new file mode 100644
index 000000000..73d78b415
--- /dev/null
+++ b/docs/one_shot_keys.md
@@ -0,0 +1,102 @@
1# One Shot Keys
2
3One shot keys are keys that remain active until the next key is pressed, and then are released. This allows you to type keyboard combinations without pressing more than one key at a time. These keys are usually called "Sticky keys" or "Dead keys".
4
5For example, if you define a key as `OSM(MOD_LSFT)`, you can type a capital A character by first pressing and releasing shift, and then pressing and releasing A. Your computer will see the shift key being held the moment shift is pressed, and it will see the shift key being released immediately after A is released.
6
7One shot keys also work as normal modifiers. If you hold down a one shot key and type other keys, your one shot will be released immediately after you let go of the key.
8
9Additionally, hitting keys five times in a short period will lock that key. This applies for both One Shot Modifiers and One Shot Layers, and is controlled by the `ONESHOT_TAP_TOGGLE` define.
10
11You can control the behavior of one shot keys by defining these in `config.h`:
12
13```c
14#define ONESHOT_TAP_TOGGLE 5 /* Tapping this number of times holds the key until tapped once again. */
15#define ONESHOT_TIMEOUT 5000 /* Time (in ms) before the one shot key is released */
16```
17
18* `OSM(mod)` - Momentarily hold down *mod*. You must use the `MOD_*` keycodes as shown in [Mod Tap](#mod-tap), not the `KC_*` codes.
19* `OSL(layer)` - momentary switch to *layer*.
20
21Sometimes, you want to activate a one-shot key as part of a macro or tap dance routine.
22
23For one shot layers, you need to call `set_oneshot_layer(LAYER, ONESHOT_START)` on key down, and `clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED)` on key up. If you want to cancel the oneshot, call `reset_oneshot_layer()`.
24
25For one shot mods, you need to call `set_oneshot_mods(MOD)` to set it, or `clear_oneshot_mods()` to cancel it.
26
27!> If you're having issues with OSM translating over Remote Desktop Connection, this can be fixed by opening the settings, going to the "Local Resources" tap, and in the keyboard section, change the drop down to "On this Computer". This will fix the issue and allow OSM to function properly over Remote Desktop.
28
29## Callbacks
30
31When you'd like to perform custom logic when pressing a one shot key, there are several callbacks you can choose to implement. You could indicate changes in one shot keys by flashing an LED or making a sound, for example.
32
33There is a callback for `OSM(mod)`. It is called whenever the state of any one shot modifier key is changed: when it toggles on, but also when it is toggled off. You can use it like this:
34
35```c
36void oneshot_mods_changed_user(uint8_t mods) {
37 if (mods & MOD_MASK_SHIFT) {
38 println("Oneshot mods SHIFT");
39 }
40 if (mods & MOD_MASK_CTRL) {
41 println("Oneshot mods CTRL");
42 }
43 if (mods & MOD_MASK_ALT) {
44 println("Oneshot mods ALT");
45 }
46 if (mods & MOD_MASK_GUI) {
47 println("Oneshot mods GUI");
48 }
49 if (!mods) {
50 println("Oneshot mods off");
51 }
52}
53```
54
55The `mods` argument contains the active mods after the change, so it reflects the current state.
56
57When you use One Shot Tap Toggle (by adding `#define ONESHOT_TAP_TOGGLE 2` in your `config.h` file), you may lock a modifier key by pressing it the specified amount of times. There's a callback for that, too:
58
59```c
60void oneshot_locked_mods_changed_user(uint8_t mods) {
61 if (mods & MOD_MASK_SHIFT) {
62 println("Oneshot locked mods SHIFT");
63 }
64 if (mods & MOD_MASK_CTRL) {
65 println("Oneshot locked mods CTRL");
66 }
67 if (mods & MOD_MASK_ALT) {
68 println("Oneshot locked mods ALT");
69 }
70 if (mods & MOD_MASK_GUI) {
71 println("Oneshot locked mods GUI");
72 }
73 if (!mods) {
74 println("Oneshot locked mods off");
75 }
76}
77```
78
79Last, there is also a callback for the `OSL(layer)` one shot key:
80
81```c
82void oneshot_layer_changed_user(uint8_t layer) {
83 if (layer == 1) {
84 println("Oneshot layer 1 on");
85 }
86 if (!layer) {
87 println("Oneshot layer off");
88 }
89}
90```
91
92If any one shot layer is switched off, `layer` will be zero. When you're looking to do something on any layer change instead of one shot layer changes, `layer_state_set_user` is a better callback to use.
93
94If you are making your own keyboard, there are also `_kb` equivalent functions:
95
96```c
97void oneshot_locked_mods_changed_kb(uint8_t mods);
98void oneshot_mods_changed_kb(uint8_t mods);
99void oneshot_layer_changed_kb(uint8_t layer);
100```
101
102As with any callback, be sure to call the `_user` variant to allow for further customizability.