Magic and Adaptive Keys
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Use a contextual rule when a single press should finish a common sequence without changing what that key does elsewhere. A dedicated magic key can handle several such sequences. An adaptive letter key can use the same mechanism while retaining its letter as the default.
Finish a Common Sequence
Section titled “Finish a Common Sequence”To finish a contraction in Chog v2, an apostrophe tells the Magic key to add “s”:
[layers.base]rules = [{ after_keys = ["'"], set = { magic = "s" } }]
[layers.base.bindings]magic = { type = "repeat" }The rules entry matches a press with after_keys and assigns the result with set. The ordinary repeat action stays in bindings.
This rule matches a particular press. Choose after_output instead if the rule should match the same text regardless of which key or chord typed it. Matching a text suffix does not remove it.
Fields
Section titled “Fields”| Field | Use |
|---|---|
layers.<layer>.rules | Add contextual rules to the layer. Define each target’s ordinary behavior in the layer’s bindings or combos. |
after_keys | Match completed presses, oldest to newest. A bare key ID refers to the containing layer; use an entry such as { press = "t", layer = "shift" } to name another layer explicitly. |
after_output | Match a suffix of the text produced so far. Use a string for a literal suffix, or an array to specify one character, class, or equivalent per position. |
word_start = true | Require the first matched press or character to begin the word. |
set | Map target IDs to outcomes, for example { x = "h" }. Use on = "combos" to target chords or branch = "tap" to select a tap-hold key’s tap action. |
prefer | When both kinds of context match a target, prefer "after_output" (default) or "after_keys". |
To replace text already emitted, use an explicit output object with delete_previous_output = true and a named immediate after_keys match. This replaces the previous ordinary press’s entire output, not just its final character. It is not available with after_output.
Reference
Section titled “Reference”Character classes and output patterns#
Character classes and equivalences#
[character_classes] and [character_equivalences]
A character class names a selected category of characters. Its expression uses ref, union, intersect, and diff, with references to earlier declarations only. Nested expressions may be empty, but every complete named class must contain at least one character. Each array string is one character or grapheme cluster.
An equivalence group lists interchangeable characters. Groups must be disjoint, and every member must also appear in a character class, a layout output, or a literal output-condition slot. Equivalence membership is used only by an explicit { equivalent = "e" } output-pattern slot, which selects the group containing that member; literals do not expand automatically, and matching never rewrites the produced output.
[character_classes]
vowels = ["a", "e", "i", "o", "u"]
accented = ["é", "ê"]
front_vowels = { intersect = [{ ref = "vowels" }, ["e", "i"]] }
[character_equivalences]
e_variants = ["e", "é", "ê"]Character-class expression#
character_classes.* = ["a", "e"] | { ref = "letters" } | { union = [...] } | { intersect = [...] } | { diff = [left, right] }Combines character classes with the same recursive expression forms as key sets. A named class must resolve to a nonempty set after its complete expression is evaluated.
Patterned previous-output context#
after_output = "suffix" | [slot, ...]
An array output context consumes one grapheme cluster per slot. A string slot is literal, { ref = "name" } selects a named character class, and { equivalent = "e" } matches any member of the disjoint equivalence group containing e. A compact string remains a literal multi-grapheme suffix. word_start = true anchors the matched suffix before its first slot at sequence start or immediately after a space; punctuation is not a separator.
Character classes and equivalences affect matching only. They do not normalize, replace, or otherwise alter the output selected by the rule. case_map and case_sensitive keep their existing matching behavior; an explicit equivalence slot still uses the group containing its declared member when case sensitivity is enabled.
rules = [{ after_output = ["q", { ref = "vowels" }, { equivalent = "e" }], word_start = true, set = { magic = "x" } }]Word-start context#
word_start = false | true
Anchors after_output before its first slot at sequence start or immediately after a space. For after_keys, the oldest matched press must begin at sequence start or after a press whose output ends in a space, and no matched press may emit a space. An anchored key-context list must name its first position. Punctuation is not a separator. The anchor does not change output.
Contextual rules#
Rules add context-dependent outputs to ordinary binding or combo defaults. Every rule has exactly one context and one operation.
Previous-key context#
after_keys = [oldest, ..., newest]
A bare ID names the direct tap of that key or chord on the containing layer. { press = "a", layer = "shift", hold = true } names an exact key or chord action. { keyset = "left", layer = "base" } matches direct taps from a named key set. Omitted layer means the containing layer, and omitted hold means false.
Values name completed output-producing presses, oldest to newest, ending immediately before the target. The last two positions may use {} wildcards or key sets; older positions must name concrete keys or chords. A context cannot be entirely wildcards. A deletion outcome requires the immediate previous slot to be named; a key set qualifies, but a wildcard there does not.
Add word_start = true to anchor the oldest matched press at sequence start or after a press whose output ends in space. No matched press may emit a space, and the first position cannot be a wildcard. Without the anchor, key-history suffixes may cross spaces. A multi-letter output still occupies one press position.
Previous-action reference#
after_keys = [{ press = "a" }]Names one stable key or chord action in an after_keys reference. A plain string is the compact same-layer, direct-tap form.
Previous-key-set reference#
after_keys = [{ keyset = "left" }]Names one authored key set in an after_keys reference.
Previous-action layer#
after_keys = [{ press = "a", layer = "shift" }]Qualifies a key or key-set reference with an exact layer. Omission means the layer containing the rule.
Previous-action tap-hold branch#
after_keys = [{ press = "qu", hold = true }]Selects the text-producing hold branch of the named tap-hold key or chord. False selects its direct tap identity.
Previous-output context#
after_output = "suffix" | [slot, ...]
Matches a produced-text suffix without removing that text. A compact string is a literal multi-grapheme suffix; an array consumes one grapheme cluster per literal, character-class, or equivalence slot. If exactly one layer declares a case map, it is selected automatically. With several maps, the rule must name one in case_map; otherwise no automatic case equivalence is added, while explicitly requested classes and equivalences still apply.
Output-context case map#
case_map = "shift"
Selects the named layer’s case map when matching after_output. With exactly one authored case map it may be omitted; with several it is required.
Set outputs#
set = { target = "output" | { type = "output", value = "..." } | outcome }Assigns one contextual outcome to each target. A string remains the compact output form. An output object may set delete_previous_output = true to replace the entire output of the immediately preceding ordinary press; its immediate after_keys slot must be named, and it cannot use after_output or a default. A completed deletion cannot be deleted or output-repeated again.
The other outcomes are { type = "repeat", repeat_kind = "output" | "keystroke" }, { type = "skip_repeat", repeat_kind = "output" | "keystroke" }, { type = "none" }, and { type = "blocked" }. none completes a no-output action without advancing completed-output history or consuming a one-shot. blocked refuses execution and cannot be rescued by a miss policy. Targets are keys by default or chord IDs when on = "combos".
Contextual outcome#
set = { target = { type = "output", value = "...", delete_previous_output = true } }An output outcome replaces the entire preceding ordinary press output when delete_previous_output = true; it does not delete one character from a multi-grapheme output. Repeat and skip-repeat may repeat output or rerun the earlier keystroke. A tap-hold target uses branch = "tap" to select its tap branch; a contextual hold branch is invalid. Tap branches may use none or blocked.
rules = [
{ after_keys = ["a"], set = { magic = { type = "output", value = "qu", delete_previous_output = true } } },
{ after_keys = ["t"], set = { again = { type = "repeat", repeat_kind = "keystroke" } } },
{ after_keys = ["x"], set = { magic = { type = "none" } } },
]Swap outputs#
swap = ["a", "b"]
Routes each target to the other target’s original literal output. Both targets must have ordinary literal defaults.
Cycle outputs#
cycle = ["a", "b", "c"]
Routes each target to the next target’s original literal output, and the final target to the first. Every target must have an ordinary literal default.
Rule target namespace#
on = "bindings" | "combos"
Selects physical key targets or per-layer chord targets. Every target must already exist in the selected namespace.
Tap-hold rule branch#
branch = "tap"
Selects the direct tap branch of a tap-hold key or chord for a contextual rule. A contextual hold branch is invalid.
Shadowed default policy#
default_when_shadowed = "blocked" | "miss"
A matching contextual rule takes the normal typing path. miss provides the target’s ordinary default only as a separate miss when the matching winner is not a blocked outcome; default_when_shadowed = "blocked" suppresses that shadowed fallback. Neither setting turns the selected outcome into blocked, and it does not fall through to another layer. Every rule for one target and tap branch must use the same policy.
Context preference#
prefer = "after_output" | "after_keys"
prefer = "after_output" is the default. Set prefer = "after_keys" to choose previous-key contexts before output-suffix contexts. All rules for one target and tap branch must use the same preference.
Context case sensitivity#
case_sensitive = false | true
case_sensitive = false allows automatic case-equivalent context matching without changing the produced output. true requires exact case. Explicit mapped-layer contexts remain exact. All rules for one target and tap branch must use the same case-sensitivity setting.
Allowed rule defaults#
A contextual target must start as an ordinary output, dead-key, none, blocked, repeat, skip-repeat, or unanchored one-shot default. Momentary, lock, anchored activation, transparent, tap-hold hold, or another contextual behavior cannot be converted into a rule target.
For one target and tap branch, the more-specific valid context wins; rule order is preserved for stable authoring and does not make the first broad match win. All rules in that group must agree on preference, case sensitivity, and shadow policy.
rules = [
{ after_keys = ["t"], set = { magic = "h" } },
{ after_keys = ["x", {}], swap = ["w", "e"] },
{ after_output = "qu", case_map = "shift", on = "combos", set = { again = "e" } },
]