### Karabiner JSON Configuration Example Source: https://karabiner.ts.evanliu.dev/index Demonstrates the structure of a Karabiner-Elements configuration file in JSON format. It includes profiles, complex modifications, rules, manipulators, and conditions. ```json { "profiles": [ { "name": "Default", "complex_modifications": { "rules": [ { "description": "Demo Rule", "manipulators": [ { "type": "basic", "from": { "key_code": "caps_lock" }, "to": [ {"key_code": "delete_or_backspace", "modifiers": ["command"]} ], "conditions": [ {"type": "variable_if", "name": "test", "value": 1} ] } ] } ] } } ] } ``` -------------------------------- ### Karabiner TypeScript Configuration Example Source: https://karabiner.ts.evanliu.dev/index Shows how to define Karabiner-Elements complex modifications using a TypeScript API. This API simplifies the creation of rules, manipulators, and conditions compared to raw JSON. ```typescript writeToProfile('Default', [ rule('Demo Rule') .manipulators([ map('⇪') .to('⌫', '⌘') .condition(ifVar('test')) ]) ]) ``` -------------------------------- ### Simlayer Configuration (JSON) Source: https://karabiner.ts.evanliu.dev/rules/simlayer Example of a simlayer configuration within `profiles.complex_modifications.rules`. This JSON structure defines the manipulators, including 'from' key codes, 'to' actions, and 'conditions' like variable states. ```json { "description": "Simlayer - a-mode", "manipulators": [ { "type": "basic", "from": {"key_code": "1", "modifiers": {"optional": ["caps_lock"]}}, "to": [{"key_code": "2"}], "conditions": [{"type": "variable_if", "name": "a-mode", "value": 1}] }, { "type": "basic", "from": { "simultaneous": [{"key_code": "a"}, {"key_code": "1"}], "simultaneous_options": { "detect_key_down_uninterruptedly": true, "key_down_order": "strict", "key_up_order": "strict_inverse", "key_up_when": "any", "to_after_key_up": [{"set_variable": {"name": "a-mode", "value": 0}}] }, "modifiers": {"optional": ["caps_lock"]} }, "to": [{"set_variable": {"name": "a-mode", "value": 1}}, {"key_code": "2"}], "parameters": {"basic.simultaneous_threshold_milliseconds": 200} } ] } ``` -------------------------------- ### Basic duoLayer Function Usage Example Source: https://karabiner.ts.evanliu.dev/rules/duo-layer This example shows the basic syntax for defining a duo layer using the `duoLayer` function, specifying two trigger keys ('f' and 'd') and chaining the `manipulators` method to define key mappings within that layer. ```javascript duoLayer('f', 'd').manipulators([ map(1).to(2) ]) ``` -------------------------------- ### Set Simlayer Threshold Time (Profile) Source: https://karabiner.ts.evanliu.dev/rules/simlayer Demonstrates how to set the `simlayer.threshold_milliseconds` globally for all simlayers within a profile using the `writeToProfile()` function. ```typescript writeToProfile( '--dry-run', // profile name [], // rules { 'simlayer.threshold_milliseconds': 100 }, // parameters ) ``` -------------------------------- ### Example of Key Aliases in a Layer Source: https://karabiner.ts.evanliu.dev/manipulators/from Shows a practical example of using key aliases within a Karabiner-Elements layer configuration. This snippet demonstrates mapping aliases to specific actions like pasting characters or triggering other keys. ```typescript layer(['z', '/'], 'emoji-mode').manipulators([ // 1 2 3 4 5 withMapper(['⌘', '⌥', '⌃', '⇧', '⇪'])((k, i) => map((i + 1) as NumberKeyValue).toPaste(k), ), // Paste the symbols instead of triggering the key withMapper(['←', '→', '↑', '↓', '␣', '⏎', '⇥', '⎋', '⌫', '⌦', '⇪'])((k) => map(k).toPaste(k), ), map(',').toPaste('‹'), // left_{modifier} map('.').toPaste('›'), // right_{modifier} ]) ``` -------------------------------- ### map() JSON Output Examples Source: https://karabiner.ts.evanliu.dev/manipulators/from Provides the JSON representation of FromEvent objects generated by various map() calls, illustrating how key codes and modifiers are structured. These examples cover simple key presses, mandatory and optional modifiers, and alias translations. ```json // map('a') { "key_code": "a" } ``` ```json // map(',', 'left_command') { "key_code": "comma", "modifiers": { "mandatory": [ "left_command"] } } ``` ```json // map(1, '⌘', '⇪') { "key_code": "1", "modifiers": { "mandatory": [ "command"], "optional": [ "caps_lock"] } } ``` ```json // map('←', { right: '⌘⌥' }) { "key_code": "left_arrow", "modifiers": { "mandatory": [ "right_command", "right_option"] } } ``` ```json // map('left_command', { optional: '⇧' }) { "key_code": "left_command", "modifiers": { "optional": [ "shift"] } } ``` ```json // map('keypad_asterisk', 'optionalAny') { "key_code": "keypad_asterisk", "modifiers": { "optional": [ "any"] } } ``` -------------------------------- ### Default Simultaneous Options Source: https://karabiner.ts.evanliu.dev/rules/simlayer Presents the default `simultaneous_options` set by `simlayer`. These options control the behavior of simultaneous key presses, including detection, ordering, and key-up conditions. ```json { "detect_key_down_uninterruptedly": true, "key_down_order": "strict", "key_up_order": "strict_inverse", "key_up_when": "any", } ``` -------------------------------- ### Mouse Motion to Scroll Manipulator JSON Output Example Source: https://karabiner.ts.evanliu.dev/manipulators/mouse_motion_to_scroll Provides an example of the JSON output generated for a `mouse_motion_to_scroll` manipulator. This JSON represents the configuration that Karabiner-Elements uses to apply the scroll behavior, including type, modifiers, conditions, and options. ```json { "type": "mouse_motion_to_scroll", "from": { "modifiers": { "mandatory": ["command"] } }, "conditions": [ {"type": "variable_if", "name": "test", "value": 1} ], "options": { "speed_multiplier": 2 } } ``` -------------------------------- ### Set Simlayer Threshold Time (Instance) Source: https://karabiner.ts.evanliu.dev/rules/simlayer Shows how to set the threshold time in milliseconds for a specific simlayer instance. The third parameter in the `simlayer` constructor defines this threshold. ```typescript simlayer('a', 'a-mode', 100) // The third parameter `threshold` in milliseconds ``` -------------------------------- ### Launch Apps with Modifier (Karabiner-TS) Source: https://karabiner.ts.evanliu.dev/editor_example=os-functionality%2Flaunch-apps-modifier This snippet defines a rule in Karabiner-TS to launch applications using a modifier key. It maps 'right_control' combined with 'c' to open 'Calendar' and 'right_control' with 'f' to open 'Finder'. No external dependencies are required beyond Karabiner-TS. ```typescript import { rule, withModifier, toApp } from 'karabiner.ts' let rules = [ rule('Launch Apps').manipulators([ withModifier('right_control')({ c: toApp('Calendar'), f: toApp('Finder'), }), ]), ] ``` -------------------------------- ### Chaining map() and to*() methods (TypeScript) Source: https://karabiner.ts.evanliu.dev/manipulators/to This example demonstrates how to chain `map*()` methods with `to*()` methods for more concise Karabiner configurations. It shows mapping key '1' to outputting key 'a', opening the 'Arc' application, and simulating a 'play_or_pause' consumer key press. ```typescript map(1).to('a').toApp('Arc').toConsumerKey('play_or_pause') ``` -------------------------------- ### Override Simultaneous Options Source: https://karabiner.ts.evanliu.dev/rules/simlayer Illustrates how to override the default `simultaneous_options` using the `options()` method in `simlayer`. This allows for fine-grained control over simultaneous key press behavior. ```typescript simlayer().options({/* ... */}) ``` -------------------------------- ### Create shell_command ToEvent (TypeScript) Source: https://karabiner.ts.evanliu.dev/manipulators/to This example shows how to create a `shell_command` ToEvent using the `to$()` function. It takes a string argument, which is the command to be executed. ```typescript to$('rm ~/temp') ``` -------------------------------- ### Create key_code ToEvent with modifiers (TypeScript) Source: https://karabiner.ts.evanliu.dev/manipulators/to This example demonstrates creating a `key_code` ToEvent using the `toKey()` function. It specifies the key code 'a' and applies Command and Shift modifiers using their shorthand representation. ```typescript toKey('a', '⌘⇧') ``` -------------------------------- ### Advanced Output Events with Karabiner.ts Source: https://context7.com/context7/karabiner_ts_evanliu_dev/llms.txt Provides examples of advanced output events in Karabiner.ts, including switching input sources, setting/unsetting variables, displaying notifications, mouse control, sticky modifiers, double clicks, cursor positioning, and system sleep. Requires the 'karabiner.ts' library. ```typescript import { map, toInputSource, toSetVar, toUnsetVar, toVar, toNotificationMessage, toRemoveNotificationMessage, toMouseKey, toStickyModifier, toCgEventDoubleClick, toMouseCursorPosition, toSleepSystem, } from 'karabiner.ts' // Switch input source map('space', '⌘').to(toInputSource({ language: 'en' })) // Set variable map('a').to(toSetVar('vim-mode', 1)) map('⎋').to(toUnsetVar('vim-mode')) map('i').toVar('insert-mode', 1) // Notification messages map('a').toNotificationMessage('hint', 'Navigation mode active') map('⎋').toRemoveNotificationMessage('hint') // Mouse movement map('h').to(toMouseKey({ x: -1000 })) map('l').to(toMouseKey({ x: 1000 })) // Sticky modifiers map('⇧').to(toStickyModifier({ left_shift: 'toggle' })) // Mouse double click map('d').to(toCgEventDoubleClick({ button: 0 })) // Move cursor position map('c').to(toMouseCursorPosition({ x: '50%', y: '50%', screen: 0 })) // Sleep system map('s', '⌘⌥⌃').to(toSleepSystem({ delay_milliseconds: 1000 })) ``` -------------------------------- ### Define simlayer with basic mapping (JSON) Source: https://karabiner.ts.evanliu.dev/rules/simlayer This JSON snippet defines a basic simlayer rule for Karabiner-Elements. It maps key '1' to output key '2' when the 'a-mode' variable is active. It also configures a simultaneous key press of 'a' and '1' to activate 'a-mode' and output key '2'. The variable 'a-mode' is reset when the 'a' key is released. ```json { "description": "Simlayer - a-mode", "manipulators": [ { "type": "basic", "from": {"key_code": "1", "modifiers": {"optional": ["any"]}}, "to": [{"key_code": "2"}], "conditions": [{"type": "variable_if", "name": "a-mode", "value": 1}] }, { "type": "basic", "from": { "simultaneous": [{"key_code": "a"}, {"key_code": "1"}], "simultaneous_options": { "detect_key_down_uninterruptedly": true, "key_down_order": "strict", "key_up_order": "strict_inverse", "key_up_when": "any", "to_after_key_up": [{"set_variable": {"name": "a-mode", "value": 0}}] }, "modifiers": {"optional": ["any"]} }, "to": [{"set_variable": {"name": "a-mode", "value": 1}}, {"key_code": "2"}], "parameters": {"basic.simultaneous_threshold_milliseconds": 200} } ] } ``` -------------------------------- ### Generate JSON for HyperLayer Key Mapping Source: https://karabiner.ts.evanliu.dev/rules/hyper-layer This JSON output represents the Karabiner Elements configuration for the `hyperLayer` example. It defines a 'basic' manipulator that sets a variable 'hyper-a' when the 'a' key is pressed with the hyper modifiers, and resets it on key release. It also defines another manipulator to map '1' to '2' when 'hyper-a' is active. ```json { "description": "Layer - hyper-a", "manipulators": [ { "type": "basic", "from": { "key_code": "a", "modifiers": {"mandatory": ["command", "option", "control", "shift"]} }, "to": [ {"set_variable": {"name": "hyper-a", "value": 1}} ], "to_after_key_up": [ {"set_variable": {"name": "hyper-a", "value": 0}} ], "to_if_alone": [ {"key_code": "a"} ] }, { "type": "basic", "from": { "key_code": "1", "modifiers": {"mandatory": ["any"]} }, "to": [ {"key_code": "2"} ], "conditions": [ {"type": "variable_if", "name": "hyper-a", "value": 1} ] } ] } ``` -------------------------------- ### Leader Key Configuration in Karabiner-TS Source: https://karabiner.ts.evanliu.dev/editor_example=vim%2Fnested-leader-key This snippet demonstrates how to configure a leader key using Karabiner-TS. It allows setting a primary key (e.g., 'l') to activate a 'leader' variable, which then enables nested key mappings. Conditions are used to manage the state of the leader key and its nested mappings, including an escape mechanism. ```typescript import { } from 'karabiner.ts' let raycastEmoji = 'raycast/emoji-symbols/search-emoji-symbols' let escape = [toUnsetVar('leader'), toRemoveNotificationMessage('leader')] let rules = [ rule('Leader Key').manipulators([ // When no leader key or nested leader key is on withCondition(ifVar('leader', 0))([ // Leader key map('l', 'Hyper') // Or mapSimultaneous(['l', ';']) ... .toVar('leader', 1) .toNotificationMessage('leader', 'Leader Key: Open, Raycast, ...'), ]), // When leader key or nested leader key is on withCondition(ifVar('leader', 0).unless())([ // Escape key(s) map('escape').to(escape), ]), // When leader key but no nested leader key is on withCondition(ifVar('leader', 1))([ // Nested leader keys withMapper(['o', 'r'])((x) => map(x) .toVar('leader', x) .toNotificationMessage('leader', `leader ${x}`), ), ]) ]) ] ``` -------------------------------- ### Generate JSON for ModifierLayer Key Mapping Source: https://karabiner.ts.evanliu.dev/rules/hyper-layer This JSON output corresponds to the `modifierLayer` example. It configures Karabiner Elements to activate a layer with 'control' and 'shift' modifiers when 'a' is pressed, setting a variable 't-s-a'. It then maps '1' to '2' when this 't-s-a' variable is active. ```json { "description": "Layer - t-s-a", "manipulators": [ { "type": "basic", "from": { "key_code": "a", "modifiers": {"mandatory": ["control", "shift"]} }, "to": [ {"set_variable": {"name": "t-s-a", "value": 1}} ], "to_after_key_up": [ {"set_variable": {"name": "t-s-a", "value": 0}} ], "to_if_alone": [ {"key_code": "a"} ] }, { "type": "basic", "from": { "key_code": "1", "modifiers": {"mandatory": ["any"]} }, "to": [ {"key_code": "2"} ], "conditions": [ {"type": "variable_if", "name": "t-s-a", "value": 1} ] } ] } ``` -------------------------------- ### Customize Simlayer Modifiers Source: https://karabiner.ts.evanliu.dev/rules/simlayer Demonstrates how to change the default optional modifiers for a simlayer. The `modifiers()` method allows specifying which modifiers are optional for a given layer. ```typescript simlayer('a', 'a-mode') .modifiers({ optional: '⇪' }) .manipulators([ map(1).to(2), ]) ``` -------------------------------- ### Define Symbols Layer with Key Mappings (Karabiner-TS) Source: https://karabiner.ts.evanliu.dev/editor_example=text-input%2Fsymbols This snippet defines a custom layer in Karabiner-TS named 'symbols', activated by the 'z' key. It maps several keys to specific symbols or actions, including arrow keys, space, enter, delete, and navigation keys. It utilizes helper functions like `withMapper` and `map` for concise configuration. ```typescript import { layer, map, withMapper } from 'karabiner.ts' let rules = [ layer('z', 'symbols').manipulators([ withMapper(['←', '→', '↑', '↓', '␣', '⏎', '⌫', '⌦'])((k) => map(k).toPaste(k), ), { ',': toPaste('‹'), '.': toPaste('›') }, withMapper({ 4: '⇥', 5: '⎋', 6: '⌘', 7: '⌥', 8: '⌃', 9: '⇧', 0: '⇪' })( (k, v) => map(k).toPaste(v), ), ]), ] ``` -------------------------------- ### mapPointingButton() for Mouse Buttons with Modifiers Source: https://karabiner.ts.evanliu.dev/manipulators/from Demonstrates the mapPointingButton() function for defining events triggered by mouse buttons. It includes an example of how to apply modifiers to a pointing button event. ```typescript mapPointingButton('button1', '⌘') ``` -------------------------------- ### Creating an Unless Condition Source: https://karabiner.ts.evanliu.dev/manipulators/condition Illustrates how to use the `unless()` method to create a condition that applies when a specific criterion is not met. This example creates a `frontmost_application_unless` condition for the 'Finder' application. ```typescript ifApp('Finder').unless() ``` -------------------------------- ### Define ModifierLayer Key Mapping in Karabiner Source: https://karabiner.ts.evanliu.dev/rules/hyper-layer The modifierLayer function allows creating key layers using specified modifier keys. This example demonstrates mapping a layer triggered by `⌃⇧` to the key 'a', and then defining a mapping within this layer to transform '1' into '2'. ```javascript modifierLayer('⌃⇧', 'a', 't-s-a').manipulators([ map(1).to(2) ]) ``` -------------------------------- ### Rule with Input Source and Application Conditions Source: https://karabiner.ts.evanliu.dev/manipulators/condition An example of defining a Karabiner-Elements rule that includes multiple conditions: an input source condition (unless English is active) and a frontmost application condition (if Finder is active). ```typescript rule('Finder', ifApp('Finder')).manipulators([ map(1).to(2).condition(ifInputSource({ language: 'en' }).unless()) ]) ``` -------------------------------- ### Define HyperLayer Key Mapping in Karabiner Source: https://karabiner.ts.evanliu.dev/rules/hyper-layer The hyperLayer function creates a custom key layer that is activated by pressing the 'hyper' key combination. It allows defining specific key mappings within this layer. This example demonstrates mapping 'a' to a hyper layer triggered by `⌘⌥⌃⇧`, and then mapping '1' to '2' within that layer. ```javascript hyperLayer('a', 'hyper-a').manipulators([ map(1).to(2) ]) ``` -------------------------------- ### Define simlayer with multiple mappings (JSON) Source: https://karabiner.ts.evanliu.dev/rules/simlayer This JSON snippet demonstrates defining a simlayer with multiple key mappings. It sets up mappings for '1' to ',' and '2' to '.' when 'a-mode' is active. It also configures simultaneous presses of 'a' with '1' or '2' to activate 'a-mode' and trigger ',' or '.' respectively. The 'a-mode' variable is reset upon releasing the 'a' key. The default simultaneous threshold is 200 milliseconds. ```json { "description": "Simlayer - a-mode", "manipulators": [ { "type": "basic", "from": {"key_code": "1", "modifiers": {"optional": ["any"]}}, "to": [{"key_code": "comma"}], "conditions": [{"type": "variable_if", "name": "a-mode", "value": 1}] }, { "type": "basic", "from": {"key_code": "2", "modifiers": {"optional": ["any"]}}, "to": [{"key_code": "period"}], "conditions": [{"type": "variable_if", "name": "a-mode", "value": 1}] }, { "type": "basic", "parameters": {"basic.simultaneous_threshold_milliseconds": 200}, "to": [{"set_variable": {"name": "a-mode", "value": 1}}, {"key_code": "comma"}], "from": { "simultaneous": [{"key_code": "a"}, {"key_code": "1"}], "simultaneous_options": { "detect_key_down_uninterruptedly": true, "key_down_order": "strict", "key_up_order": "strict_inverse", "key_up_when": "any", "to_after_key_up": [{"set_variable": {"name": "a-mode", "value": 0}}] }, "modifiers": {"optional": ["any"]} } }, { "type": "basic", "parameters": {"basic.simultaneous_threshold_milliseconds": 200}, "to": [ {"set_variable": {"name": "a-mode", "value": 1}}, {"key_code": "period"} ], "from": { "simultaneous": [{"key_code": "a"}, {"key_code": "2"}], "simultaneous_options": { "detect_key_down_uninterruptedly": true, "key_down_order": "strict", "key_up_order": "strict_inverse", "key_up_when": "any", "to_after_key_up": [{"set_variable": {"name": "a-mode", "value": 0}}] }, "modifiers": {"optional": ["any"]} } } ] } ``` -------------------------------- ### Configure Duo Modifiers with Karabiner-TS Source: https://karabiner.ts.evanliu.dev/editor_example=modifier-keys%2Fduo-modifiers This TypeScript code snippet defines custom keybindings using the `duoModifiers` function from the `karabiner.ts` library. It maps combinations of modifier keys (⌘, ⌃, ⌥, ⇧) with letter keys to new key sequences. This allows for creating complex shortcuts and optimizing workflow by assigning multiple functions to fewer keys. ```typescript import { } from 'karabiner.ts' let rules = [ rule('duo-modifiers').manipulators( duoModifiers({ '⌘': ['fd', 'jk'], // ⌘ first as used the most '⌃': ['fs', 'jl'], // ⌃ second as Vim uses it '⌥': ['fa', 'j;'], // ⌥ last as used the least '⇧': ['ds', 'kl'], '⌘⇧': ['gd', 'hk'], '⌃⇧': ['gs', 'hl'], '⌥⇧': ['ga', 'h;'], '⌘⌥': ['vc', 'm,'], '⌘⌃': ['vx', 'm.'], '⌥⌃': ['cx', ',.'], '⌘⌥⌃': ['vz', 'm/'], }), ), ] function duoModifiers( v: Partial< Record< '⌘' | '⌥' | '⌃' | '⇧' | MultiModifierAlias, `${LetterKeyCode | KeyAlias}${LetterKeyCode | KeyAlias}`[] ``` -------------------------------- ### Configure Layer Key Behavior with layer().configKey() Source: https://karabiner.ts.evanliu.dev/rules/layer Illustrates how to change the behavior of the layer activation key when it's tapped alone using the `configKey()` method. This example maps the 'a' key to trigger 'b' with the 'command' modifier when tapped by itself, while still functioning as a layer activator when held. ```typescript layer('a', 'a-mode') .configKey((v) => v.toIfAlone('b', '⌘'), true) .manipulators([ map(1).to(2), ]) ``` ```json { "description": "Layer - a-mode", "manipulators": [ { "type": "basic", "from": { "key_code": "a" }, "to": [ { "set_variable": {"name": "a-mode", "value": 1} } ], "to_after_key_up": [ { "set_variable": {"name": "a-mode", "value": 0} } ], "to_if_alone": [ { "key_code": "b", "modifiers": ["command"] } ] }, { "type": "basic", "from": {"key_code": "1"}, "to": [ {"key_code": "2"} ], "conditions": [ { "type": "variable_if", "name": "a-mode", "value": 1 } ] } ] } ``` -------------------------------- ### Caps Lock to Hyper Key Example in Karabiner-TS Source: https://context7.com/context7/karabiner_ts_evanliu_dev/llms.txt A practical example demonstrating how to reconfigure the Caps Lock key to act as a Hyper Key (Shift + Control + Option + Command) when held, and as Escape when tapped alone. This is a common and powerful keyboard customization. ```typescript import { writeToProfile, rule, map } from 'karabiner.ts' writeToProfile('Default', [ rule('Caps Lock → Hyper').manipulators([ map('caps_lock') .toHyper() .toIfAlone('caps_lock'), // or .toIfAlone('escape') ]), ]) ``` -------------------------------- ### Define Launch App Layer with Karabiner-TS Source: https://karabiner.ts.evanliu.dev/examples/os-functionality/launch-apps-layer Defines a layer named 'launch-app' using Karabiner-TS. When the 'l' key is held, pressing 'c' launches the Calendar app, and pressing 'f' launches the Finder app. This requires the `toApp` function, which is part of the Karabiner-Elements configuration. ```typescript let rules = [ layer('l', 'launch-app').manipulators({ c: toApp('Calendar'), f: toApp('Finder'), }), ] ``` -------------------------------- ### Key Alias Mapping Source: https://karabiner.ts.evanliu.dev/manipulators/from Lists common key aliases used in Karabiner-Elements configuration, such as ⌘ for command and ⇧ for shift, along with their corresponding string representations for use in configuration files. ```text ⌘ command ⌥ option ⌃ control ⇧ shift ⇪ caps_lock ↑ up_arrow ↓ down_arrow ← left_arrow → right_arrow ⇞ page_up ⇟ page_down ↖ home ↘ end ⏎ return_or_enter ⎋ escape ⌫ delete_or_backspace ⌦ delete_forward ⇥ tab ␣ spacebar - hyphen = equal_sign [ open_bracket ] close_bracket \ backslash ; semicolon ' quote ` grave_accent_and_tilde , comma . period / slash ``` -------------------------------- ### Executing Shell Commands with Karabiner.ts Source: https://context7.com/context7/karabiner_ts_evanliu_dev/llms.txt Demonstrates how to execute shell commands, open applications, and paste text using `to$()`, `toApp()`, and `toPaste()` in Karabiner.ts. Supports chaining multiple commands. Requires the 'karabiner.ts' library. ```typescript import { map, to$, toApp, toPaste } from 'karabiner.ts' // Raw shell command map('a').to$('rm ~/temp') // Open application map('f', '⌘⇧').toApp('Finder') map('c', '⌘⇧').toApp('Calendar') // Paste text (preserves clipboard) map('e').toPaste('✨') map('h').toPaste('Hello, World!') // Multiple shell commands map('a') .toApp('Finder') .to$('say "Finder opened"') ``` -------------------------------- ### Helper functions for common shell_commands (TypeScript) Source: https://karabiner.ts.evanliu.dev/manipulators/to These functions provide convenient ways to create specific shell command ToEvents. `toApp()` is used to open an application, and `toPaste()` simulates pasting text via the clipboard. ```typescript toApp() // open -a {}.app toPaste() // Paste text via clipboard ``` -------------------------------- ### Define a rule with conditions Source: https://karabiner.ts.evanliu.dev/rules/rule Conditions applied to `rule()` are inherited by all manipulators within that group. This example shows how to add a variable condition using `ifVar()`. The generated JSON includes these conditions in each manipulator. ```typescript rule('Demo', ifVar('test')).manipulators([ map(1).to(2), ]) // or rule().condition() ``` ```json { "description": "Demo", "manipulators": [ { "type": "basic", "from": { "key_code": "1" }, "to": [ { "key_code": "2" } ], "conditions": [ { "type": "variable_if", "name": "test", "value": 1 } ] } ] } ``` -------------------------------- ### JSON outputs for common shell_command ToEvents (JSON) Source: https://karabiner.ts.evanliu.dev/manipulators/to These JSON outputs illustrate the `shell_command` ToEvents generated by `toApp()` and `toPaste()`. `toApp()` constructs an `open` command, while `toPaste()` generates an `osascript` command to handle clipboard manipulation and pasting. ```json // toApp('Finder') { "shell_command": "open -a \"Finder\".app" } // toPaste('✨') { "shell_command": "osascript -e '\nset prev to the clipboard\nset the clipboard to \"✨\"\ntell application \"System Events\"\n keystroke \"v\" using command down\n delay 0.1\nend tell\nset the clipboard to prev'" } ``` -------------------------------- ### Define a basic rule with manipulators Source: https://karabiner.ts.evanliu.dev/rules/rule Use the `rule()` function to define a group of manipulators. The provided example demonstrates mapping key '1' to key '2'. Manipulators cannot be empty within a rule. ```typescript rule('Demo').manipulators([ map(1).to(2), ]) ``` ```json { "description": "Demo", "manipulators": [ { "type": "basic", "from": { "key_code": "1" }, "to": [ { "key_code": "2" } ] } ] } ``` -------------------------------- ### Configure DuoLayer with Custom Delay Time Source: https://karabiner.ts.evanliu.dev/rules/delayed-layer Sets a custom delay time in milliseconds for a duoLayer activation. This overrides the default delay setting, allowing for finer control over when the layer is triggered. The example sets a 150ms delay. ```typescript duoLayer('f', 'd') .delay(150) // 150ms delay instead of default 200ms ``` -------------------------------- ### Custom Escape Keys for Leader Mode - Karabiner-ts Source: https://karabiner.ts.evanliu.dev/rules/leader-mode Defines custom keys to deactivate leader mode. By default, 'escape' and 'caps_lock' are used. This example sets 'spacebar' and 'return_or_enter' as the keys to exit the leader mode layer. ```typescript hyperLayer('o') .leaderMode({ escape: ['spacebar', 'return_or_enter'] }) ``` -------------------------------- ### Application Conditions with Karabiner-TS Source: https://context7.com/context7/karabiner_ts_evanliu_dev/llms.txt Shows how to apply key mappings conditionally based on the currently active application. Supports matching by bundle identifier, file path, or using 'unless' for inverse logic. Essential for app-specific shortcuts. ```typescript import { map, ifApp } from 'karabiner.ts' // Active if frontmost app matches map('h').to('←').condition(ifApp('com.apple.finder')) // Bundle identifiers map('j').to('↓').condition(ifApp({ bundle_identifiers: ['com.apple.Safari'] })) // File paths map('k').to('↑').condition(ifApp({ file_paths: ['/Applications/Chrome.app'] })) // Unless (opposite condition) map('a').to('b').condition(ifApp('Finder').unless()) ``` -------------------------------- ### Device Conditions with Karabiner-TS Source: https://context7.com/context7/karabiner_ts_evanliu_dev/llms.txt No description ```typescript import { map, ifDevice, ifDeviceExists } from 'karabiner.ts' // Specific device map('a').to('b').condition(ifDevice({ product_id: 123 })) // Device exists map('a').to('x').condition(ifDeviceExists({ vendor_id: 1452 })) // Unless map('a').to('y').condition(ifDevice({ product_id: 456 }).unless()) ``` -------------------------------- ### Basic and Advanced Key Mapping with Karabiner.ts map() Source: https://context7.com/context7/karabiner_ts_evanliu_dev/llms.txt Shows how to map keyboard keys using the `map()` function in Karabiner.ts. Supports basic mappings, mandatory/optional modifiers, left/right specific modifiers, and full event definitions. Requires the 'karabiner.ts' library. ```typescript import { map, toKey } from 'karabiner.ts' // Basic key mapping map('a') // { key_code: "a" } // With mandatory modifiers map(',', 'left_command') // comma with left command map(1, '⌘', '⇪') // number 1 with command and caps_lock // With left/right specific modifiers map('←', { right: '⌘⌥' }) // left arrow with right command + option // With optional modifiers map('left_command', { optional: '⇧' }) // Optional any modifier map('keypad_asterisk', 'optionalAny') // or '??' // Full from event definition map({ key_code: 'a', modifiers: { mandatory: ['left_command', 'shift'], optional: ['caps_lock'] } }) ``` -------------------------------- ### Disabling Single Tap in Double Tap Configuration Source: https://karabiner.ts.evanliu.dev/manipulators/double-tap Illustrates how to disable the single-tap action when using mapDoubleTap() by passing null to the singleTap() method. This ensures that the key combination must be pressed twice to trigger the defined action, as shown in the example for Command+Q. ```javascript mapDoubleTap('q', '⌘').to('q', '⌘') .singleTap(null) // Must pressing command-q twice to quit application ``` -------------------------------- ### Setting Simultaneous Threshold via writeToProfile() Source: https://karabiner.ts.evanliu.dev/manipulators/from Demonstrates how to set the simultaneous threshold parameter globally for a profile using the writeToProfile() function, offering an alternative to setting it directly in mapSimultaneous(). ```typescript writeToProfile( '--dry-run', // profile name [], // rules { 'basic.simultaneous_threshold_milliseconds': 100 }, // parameters ) ``` -------------------------------- ### Add Modifiers to a Key Layer with layer().modifiers() Source: https://karabiner.ts.evanliu.dev/rules/layer Shows how to define a key layer that is only active when a specific key and additional modifier keys are pressed simultaneously. The example uses the 'a' key with the 'command' modifier, and manipulators within this layer also require any modifier to be pressed. ```typescript layer('a', 'a-mode') .modifiers('⌘') .manipulators([ map(1).to(2), ]) ``` ```json { "description": "Layer - a-mode", "manipulators": [ { "type": "basic", "from": { "key_code": "a", "modifiers": {"mandatory": ["command"]} }, "to": [ {"set_variable": {"name": "a-mode", "value": 1}} ], "to_after_key_up": [ {"set_variable": {"name": "a-mode", "value": 0}} ], "to_if_alone": [ {"key_code": "a"} ] }, { "type": "basic", "from": { "key_code": "1", "modifiers": {"mandatory": ["any"]} }, "to": [ {"key_code": "2"} ], "conditions": [ {"type": "variable_if", "name": "a-mode", "value": 1} ] } ] } ``` -------------------------------- ### App Launcher with Modifier Key (Karabiner.ts) Source: https://context7.com/context7/karabiner_ts_evanliu_dev/llms.txt Creates an application launcher triggered by the 'Meh' modifier key combined with specific character keys. It maps 'c' to Calendar, 'f' to Finder, 'm' to Mail, 's' to Safari, and 't' to Terminal. This utilizes the 'withMapper' and 'toApp' functions from 'karabiner.ts'. ```typescript import { writeToProfile, rule, withMapper, map } from 'karabiner.ts' writeToProfile('Default', [ rule('Meh + Key = Launch App').manipulators([ withMapper({ c: 'Calendar', f: 'Finder', m: 'Mail', s: 'Safari', t: 'Terminal', })((key, app) => map(key, 'Meh').toApp(app) ), ]), ]) ``` -------------------------------- ### Launch Apps with Modifier Keys in Karabiner-ts Source: https://karabiner.ts.evanliu.dev/examples/os-functionality/launch-apps-modifier This rule defines how to launch specific applications (Calendar, Finder) when a modifier key (right_control) is pressed along with another key (c or f). It utilizes the `rule` and `manipulators` functions from Karabiner-ts. ```json let rules = [ rule('Launch Apps').manipulators([ withModifier('right_control')({ c: toApp('Calendar'), f: toApp('Finder'), }), ]), ] ``` -------------------------------- ### Customizing Double Tap Delay Time Source: https://karabiner.ts.evanliu.dev/manipulators/double-tap Explains how to set a custom delay time for the double-tap action. The delay determines how quickly the second tap must occur to be recognized as a double-tap. The example shows setting the delay to 100 milliseconds directly in mapDoubleTap() or using the delay() method. ```javascript mapDoubleTap('⇪', 100) // The last parameter .delay(100) // Can also be set with another method ``` -------------------------------- ### Define a Basic Key Layer with layer() Source: https://karabiner.ts.evanliu.dev/rules/layer Demonstrates how to create a simple key layer using the layer() function. This layer is activated when the 'a' key is held down, and subsequent key presses are mapped to different outputs. It utilizes a variable to track the active layer state. ```typescript layer('a', 'a-mode').manipulators([ map(1).to(2) // Only when key 'a' is pressed and held ]) ``` ```json { "description": "Layer - a-mode", "manipulators": [ { "type": "basic", "from": { "key_code": "a" }, "to": [ {"set_variable": {"name": "a-mode", "value": 1}} ], "to_after_key_up": [ {"set_variable": {"name": "a-mode", "value": 0}} ], "to_if_alone": [ {"key_code": "a"} ] }, { "type": "basic", "from": {"key_code": "1"}, "to": [{"key_code": "2"}], "conditions": [ { "type": "variable_if", "name": "a-mode", "value": 1 } ] } ] } ``` -------------------------------- ### Consumer Key Mapping in Karabiner.ts Source: https://context7.com/context7/karabiner_ts_evanliu_dev/llms.txt Illustrates mapping consumer keys (media controls, system functions) using `mapConsumerKey()` in Karabiner.ts. Supports mapping to standard keys and including modifiers. Requires the 'karabiner.ts' library. ```typescript import { mapConsumerKey } from 'karabiner.ts' // Play/pause media mapConsumerKey('play_or_pause').to('a') // Volume controls mapConsumerKey('volume_increment') mapConsumerKey('volume_decrement') // With modifiers mapConsumerKey('menu', '⌘', 'any') ``` -------------------------------- ### Configure DuoLayer with Delay Mode and Manipulators Source: https://karabiner.ts.evanliu.dev/rules/delayed-layer Activates a delayed layer for duoLayer with custom key mappings. The delay mode prevents accidental activation during fast typing. A notification is recommended when using delay mode. This example maps 'h' to left arrow and 'l' to right arrow. ```typescript duoLayer('j', 'k') .delay() .notification() // Notification is recommended with delay mode .manipulators({ h: toKey('left_arrow'), l: toKey('right_arrow'), }) ``` -------------------------------- ### Configuring Single Tap with Double Tap Source: https://karabiner.ts.evanliu.dev/manipulators/double-tap Shows how to use mapDoubleTap() with the singleTap() method to define a specific action for a single key press, distinct from the double-tap action. This allows for more complex keybinding scenarios. The example maps Caps Lock double-tap to Escape, while a single tap triggers 'q' with the Command modifier. ```javascript mapDoubleTap('⇪').to('⎋') .singleTap(toKey('q', '⌘')) ``` -------------------------------- ### Helper functions for common ToEvents (TypeScript) Source: https://karabiner.ts.evanliu.dev/manipulators/to These are common helper functions to create specific `ToEvent` configurations. `toHyper()` maps to ⌘⌥⌃⇧, `toMeh()` to ⌥⌃⇧, `toSuperHyper()` to ⌘⌥⌃⇧fn, and `toNone()` outputs `vk_none`. ```typescript toHyper() // ⌘⌥⌃⇧ toMeh() // ⌥⌃⇧ toSuperHyper() // ⌘⌥⌃⇧fn toNone() // vk_none ``` -------------------------------- ### mapConsumerKey() JSON Output Source: https://karabiner.ts.evanliu.dev/manipulators/from Presents the JSON structure for a FromEvent object created using mapConsumerKey(), detailing the consumer key code and its associated modifiers. ```json { "consumer_key_code": "menu", "modifiers": { "mandatory": ["command"], "optional": ["any"] } } ``` -------------------------------- ### Create key_code ToEvent JSON output (JSON) Source: https://karabiner.ts.evanliu.dev/manipulators/to This JSON object represents the output of `toKey('a', '⌘⇧')`. It specifies the key code as 'a' and includes an array for modifiers, listing 'command' and 'shift'. ```json { "key_code": "a", "modifiers": ["command", "shift"] } ```