### Install Karabiner DriverKit Daemon as LaunchDaemon Source: https://github.com/jtroo/kanata/blob/main/docs/setup-macos.md Set up the Karabiner DriverKit daemon to run automatically at boot by copying its plist file, setting ownership, and bootstrapping it with launchctl. This ensures the daemon starts persistently. ```sh sudo cp cfg_samples/karabiner-vhid-daemon.plist \ /Library/LaunchDaemons/org.pqrs.Karabiner-VirtualHIDDevice-Daemon.plist ``` ```sh sudo chown root:wheel \ /Library/LaunchDaemons/org.pqrs.Karabiner-VirtualHIDDevice-Daemon.plist ``` ```sh sudo launchctl bootstrap system \ /Library/LaunchDaemons/org.pqrs.Karabiner-VirtualHIDDevice-Daemon.plist ``` -------------------------------- ### Example Input Chords Configuration Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc An example demonstrating the `defchordsv2` configuration with two chords. The first chord triggers action 'c' when 'a' and 's' are pressed within 200ms, releasing on all key releases. The second chord triggers a 'hello' macro when 'a', 's', and 'd' are pressed within 250ms, releasing on the first key release. ```lisp (defchordsv2 (a s) c 200 all-released (non-chord-layer) (a s d) (macro h e l l o) 250 first-release (non-chord-layer) (s d f) (macro b y e) 400 first-release (non-chord-layer) ) ``` -------------------------------- ### Switch Action Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Provides a concrete example of a switch action with multiple cases, demonstrating the use of 'and', 'or', 'break', and 'fallthrough'. ```source (defalias swt (switch ;; case 1 ((and a b (or c d) (or e f))) @ac1 break ;; case 2 (a b c) @ac2 fallthrough ;; case 3 () @ac3 break ) ) ``` -------------------------------- ### macOS Specific Configuration Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Example of platform-specific configuration for macOS, overriding key bindings for word navigation. ```lisp (platform (macos) ;; Only on macos, use command arrows to jump/delete words ;; because command is used for so many other things ;; and it's weird that these cases use alt. (defoverrides (lmet bspc) (lalt bspc) (lmet left) (lalt left) (lmet right) (lalt right) ) ) ``` -------------------------------- ### Example: Query and Switch Layers Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Demonstrates how to query and switch layers using the Kanata TCP server. ```bash .Example - Query and switch layers: [source,bash] ---- ``` -------------------------------- ### Comprehensive Mouse Actions Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc An example demonstrating various mouse actions including wheel movements, basic and accelerated mouse movements, setting absolute position, and adjusting mouse speed. ```source (defalias mwu (mwheel-up 50 120) mwd (mwheel-down 50 120) mwl (mwheel-left 50 120) mwr (mwheel-right 50 120) ms↑ (movemouse-up 1 1) ms← (movemouse-left 1 1) ms↓ (movemouse-down 1 1) ms→ (movemouse-right 1 1) ma↑ (movemouse-accel-up 1 1000 1 5) ma← (movemouse-accel-left 1 1000 1 5) ma↓ (movemouse-accel-down 1 1000 1 5) ma→ (movemouse-accel-right 1 1000 1 5) sm (setmouse 32228 32228) fst (movemouse-speed 200) ) (deflayer mouse _ @mwu @mwd @mwl @mwr _ _ _ _ _ @ma↑ _ _ _ _ pgup bck _ fwd _ _ _ _ @ma← @ma↓ @ma→ _ _ _ pgdn mlft _ mrgt mmid _ mbck mfwd _ @ms↑ _ _ @fst _ mltp _ mrtp mmtp _ mbtp mftp @ms← @ms↓ @ms→ _ _ _ _ _ _ _ ) ``` -------------------------------- ### Chords v2 with Virtual Keys Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc This example shows how to integrate `defchordsv2` with virtual keys to ensure chord actions are processed by actions like `tap-hold-release`. It defines virtual keys for backspace and delete and maps chords to trigger these virtual keys. ```lisp (defcfg concurrent-tap-hold yes) (defsrc) (deflayermap (base) caps (tap-hold-release 0 200 esc lctl)) ;; defines a vkey named v-$key, example v-bspc ;; and an alias @v-bspc that press and and releases the v-key ;; within on-press and on-release respectively. (deftemplate v- (key) (defvirtualkeys (concat v- $key) $key) (defalias (concat v- $key) (multi (on-press press-vkey (concat v- $key)) (on-release release-vkey (concat v- $key)))) ) (t! v- bspc) (t! v- del) (defchordsv2 (j k) @v-bspc 75 first-release () (s d) @v-del 75 first-release () ) ``` -------------------------------- ### Manually Start Karabiner DriverKit Daemon Source: https://github.com/jtroo/kanata/blob/main/docs/setup-macos.md Quickly test the Karabiner DriverKit daemon by starting it manually. This command is not persistent and will not survive a reboot. ```sh sudo "/Library/Application Support/org.pqrs/Karabiner-DriverKit-VirtualHIDDevice/Applications/Karabiner-VirtualHIDDevice-Daemon.app/Contents/MacOS/Karabiner-VirtualHIDDevice-Daemon" & ``` -------------------------------- ### Environment Variable Conditional Alias Examples Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Examples of environment-conditional configuration, defining aliases based on the 'LAPTOP' environment variable. ```lisp (environment (LAPTOP lp1) (defalias met @lp1met) ) (environment (LAPTOP lp2) (defalias met @lp2met) ) ``` -------------------------------- ### Install with 'cmd' feature flag Source: https://github.com/jtroo/kanata/blob/main/README.md Use this command to install Kanata with the 'cmd' feature enabled. This flag is added using the --features argument. ```bash cargo install --features cmd ``` -------------------------------- ### Basic Zippychord Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc A simple zippychord configuration mapping 'gi' to 'git'. This demonstrates how typed keys are backspaced and the output is typed. ```bash gi git ``` -------------------------------- ### Example Kanata CLI Flags for Win-Tray Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Demonstrates how to pass command-line arguments to the Kanata tray application when launching it via a shortcut. This example disables delay and enables debug mode. ```bash "C:\Program Files\kanata\kanata.exe" -d -n ``` -------------------------------- ### Install Kanata as a LaunchDaemon Source: https://github.com/jtroo/kanata/blob/main/docs/setup-macos.md Copies the sample LaunchDaemon plist, sets ownership, and bootstraps the service for login-time startup. Ensure the paths in ProgramArguments are correctly set before execution. ```sh sudo cp cfg_samples/kanata.plist /Library/LaunchDaemons/dev.kanata.kanata.plist sudo chown root:wheel /Library/LaunchDaemons/dev.kanata.kanata.plist sudo launchctl bootstrap system /Library/LaunchDaemons/dev.kanata.kanata.plist ``` -------------------------------- ### Inertial Mouse Wheel Configuration Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Provides an example configuration for inertial mouse wheel scrolling using variables for velocity and multipliers. ```adoc (defvar mw-initial-v 3 mw-maximum-v 1200 mw-accel 1.15 mw-decel 0.93) (defalias mwu (mwheel-accel-up $mw-initial-v $mw-maximum-v $mw-accel $mw-decel) mwd (mwheel-accel-down $mw-initial-v $mw-maximum-v $mw-accel $mw-decel)) ``` -------------------------------- ### Install with combined feature flags Source: https://github.com/jtroo/kanata/blob/main/README.md To combine multiple feature flags, use a single --features argument with features separated by commas. This example enables both 'cmd' and 'interception_driver'. ```bash cargo install --features cmd,interception_driver ``` -------------------------------- ### Windows and macOS/Linux Specific Alias Examples Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Demonstrates platform-specific aliases for running scripts, with different commands for Windows and Unix-like systems. ```lisp (platform (win winiov2 wintercept) (defalias run-my-script (cmd #| something involving powershell |#)) ) (platform (macos linux) (defalias run-my-script (cmd #| something involving bash |#)) ) ``` -------------------------------- ### Example: Trigger Text Expansion Macro Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Demonstrates how to define a virtual key macro in the configuration and then trigger it using a TCP client command. ```clojure ;; In your config: (defvirtualkeys email-sig (macro S-b e s t spc r e g a r d s) ) ;; From TCP client: echo '{"ActOnFakeKey":{"name":"email-sig","action":"Tap"}}' | nc localhost 7070 ``` -------------------------------- ### Install Xcode Command Line Tools Source: https://github.com/jtroo/kanata/blob/main/docs/setup-macos.md Install the Xcode Command Line Tools if you plan to build Kanata from source. This is a prerequisite for compiling the project. ```sh xcode-select --install ``` -------------------------------- ### Example Input for Advanced Configuration Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Provides sample text to test the context-dependent chording configuration. Typing these sequences demonstrates how the configuration handles capitalization, punctuation, and multi-word output. ```Plain Text day; Day; Tuesday. day hello hello day Hello day. hello Tuesday Hello Monday; ``` -------------------------------- ### Zippychord Activation Sequence Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Illustrates typing event sequences that will activate the 'gi' to 'git' zippychord, resulting in the output 'git'. ```bash (press g) (press i) ``` ```bash (press i) (press g) ``` -------------------------------- ### Unmod Action Usage Examples Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Provides examples of using the unmod action for outputting specific keys without modifiers, including a macro for dead keys and unshifted symbols. ```lisp (defalias ;; holding shift and tapping a @um1 key will still output 1. um1 (unmod 1) ;; dead keys é (as opposed to using AltGr) that outputs É when shifted dké (macro (unmod ') e) ;; In ISO German QWERTZ, force unshifted symbols even if shift is held { (unshift ralt 7) [ (unshift ralt 8) ) ``` -------------------------------- ### Installing the Interception Driver on Windows Source: https://github.com/jtroo/kanata/blob/main/docs/release-template.md These commands are used to install the Interception driver on Windows. It requires administrator privileges and a system reboot to complete the installation. ```bash "command line installer/install-interception.exe" ``` -------------------------------- ### Input Device Matcher Examples Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Illustrates the available matchers for `definputdevices`. These include matching by device name, hex hash, vendor ID, and product ID, allowing precise identification of input devices. ```lisp (name "...") (hash "...") (vendor_id N) (product_id N) ``` -------------------------------- ### Clipboard Macro Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc An example macro demonstrating how to use clipboard actions to paste content twice with a space and restore the original clipboard. This showcases combining multiple clipboard operations. ```kanata ;; The example below is a macro that pastes the content of the clipboard ;; twice with a space in between, ;; while restoring the original clipboard content at the end. ``` -------------------------------- ### Unmod Action Syntax Examples Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Demonstrates the basic syntax for the unmod action, which outputs keys while temporarily deactivating modifiers. ```lisp (unmod $key1 $key2 ... $keyN) (unmod ($mod1 $mod2 ... $modN) $key1 $key2 ... $keyN) ``` -------------------------------- ### Example Macro Definitions Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Demonstrates defining aliases for macros to type specific strings, including URLs, sentences with capitalization, and keyboard shortcuts. ```kanata (defalias : S-; 8 8 0 0 🙃 (unicode 🙃) ;; Type "http://localhost:8080" lch (macro h t t p @: / / 100 l o c a l h o s t @: @8 @0 @8 @0) ;; Type "I am HAPPY my FrIeNd 🙃" hpy (macro S-i spc a m spc S-(h a p p y) spc m y S-f r S-i e S-n d spc @🙃) ;; alt-tab(x3) and alt-shift-tab(x3) with macro tfd (macro A-(tab 200 tab 200 tab)) tbk (macro A-S-(tab 200 tab 200 tab)) ) ``` -------------------------------- ### Input Operation Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Demonstrates operating on inputs, including real and virtual keys, within a switch statement. ```Kanata Lisp (defalias switch-input-example (switch ((input real lctl)) $ac1 break ((input virtual vk1)) $ac2 break () $ac3 break ) ) ``` -------------------------------- ### Example: Remap QWERTY to Dvorak Layout Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Demonstrates remapping the US QWERTY layout to the Dvorak layout using defsrc and deflayer. The deflayer defines the new key behaviors. ```kanata (defsrc grv 1 2 3 4 5 6 7 8 9 0 - = bspc tab q w e r t y u i o p [ ] \ caps a s d f g h j k l ; ' ret lsft z x c v b n m , . / rsft lctl lmet lalt spc ralt rmet rctl ) (deflayer dvorak grv 1 2 3 4 5 6 7 8 9 0 [ ] bspc tab ' , . p y f g c r l / = \ caps a o e u i d h t n s - ret lsft ; q j k x b m w v z rsft lctl lmet lalt spc ralt rmet rctl ) ``` -------------------------------- ### Serve Website Files with Python Source: https://github.com/jtroo/kanata/blob/main/wasm/README.md Starts a local HTTP server to serve website files, useful for testing the generated WASM output. Replace with your desired port number. ```bash python -m http.server ``` -------------------------------- ### Run Kanata with a Sample Configuration Source: https://github.com/jtroo/kanata/blob/main/docs/setup-macos.md Perform a smoke test by running Kanata with a sample configuration file. This verifies that Kanata starts correctly and the Karabiner driver is functioning. ```sh sudo kanata -c cfg_samples/simple.kbd ``` -------------------------------- ### External Tool Integration Examples Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Shows how to use `push-msg` to trigger external tools like Raycast extensions or control media playback. This enables keyboard shortcuts to interact with other applications. ```kanata (defalias ;; Trigger a Raycast extension raycast-clip (push-msg "raycast:clipboard-history") ;; Control media playback via external script play-pause (push-msg "media:toggle") next-track (push-msg "media:next") ;; Switch keyboard layouts via external tool layout-next (push-msg "xkb:next-layout") ) ``` -------------------------------- ### One-Shot Action Examples Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Demonstrates various one-shot action configurations, including layer activation, single key presses, and different trigger conditions (press/release, cancel). ```clojure (defalias os1 (one-shot 500 (layer-while-held another-layer)) os2 (one-shot-press 2000 lsft) os3 (one-shot-release 2000 lctl) os4 (one-shot-press-pcancel 2000 lalt) os5 (one-shot-release-pcancel 2000 lmet) ) ``` -------------------------------- ### Build and Install Kanata from Source Source: https://github.com/jtroo/kanata/blob/main/docs/setup-macos.md Clone the Kanata repository, build the release version using Cargo, and then copy the compiled binary to /usr/local/bin. This method is for users who prefer to build from source. ```sh git clone https://github.com/jtroo/kanata && cd kanata ``` ```sh cargo build --release ``` ```sh sudo cp target/release/kanata /usr/local/bin/kanata ``` -------------------------------- ### Make Kanata Binary Executable and Install Source: https://github.com/jtroo/kanata/blob/main/docs/setup-macos.md Make the downloaded Kanata binary executable and move it to a directory in your system's PATH, such as /usr/local/bin. This makes the 'kanata' command available system-wide. ```sh chmod +x kanata-macos-arm64 ``` ```sh sudo mv kanata-macos-arm64 /usr/local/bin/kanata ``` -------------------------------- ### Overlapping Zippychord Configuration Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Demonstrates how zippychord supports fully overlapping chords and sequences, allowing for complex git command shortcuts. ```bash gi git gi s git status gi c git checkout gi c b git checkout -b gi c a git commit --amend gi c n git commit --amend --no-edit gi c a m git commit --amend -m 'FIX_THIS_COMMIT_MESSAGE' ``` -------------------------------- ### Kanata Command Line with Multiple Config Files Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Provides an example of how to specify multiple configuration files when launching Kanata from the command line. The order in which files are listed is significant for actions like `lrld-num`. ```bash kanata -c startup.cfg -c 2nd.cfg -c 3rd.cfg ``` -------------------------------- ### Tap-Hold Workaround Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Demonstrates a workaround for potential Linux issues with tap-hold by nesting it within a 'multi' action and using a no-op key like 'f24'. ```lisp (multi f24 (tap-hold ...)) ``` -------------------------------- ### Setting Environment Variables in Terminal Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Provides an example command for setting environment variables within the current terminal session. ```bash ``` -------------------------------- ### Key Timing Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Illustrates using key-timing to check the recency and timing of typed keys within a switch statement. ```Kanata Lisp (defalias swh (switch ((key-timing 1 less-than 200)) S-a break ((key-timing 1 greater-than 500)) S-b break ((key-timing 2 lt 1000)) S-c break ((key-timing 8 gt 2000)) (macro d d d) break () XX break ) ) ``` -------------------------------- ### Base Layer Check Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Shows how to use the 'base-layer' list item to determine if the current layer is the base layer. ```Kanata Lisp (defalias switch-base-layer-example (switch ((base-layer)) x break ((layer other)) y break () z break ) ) ``` -------------------------------- ### Zippychord Non-Activation Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Shows a typing event sequence that would not result in zippychord activation, contrasting with valid activation sequences. ```bash (press g) (release g) (press i) ``` -------------------------------- ### Empty Configuration Definition Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc An example of an empty defcfg entry, which can be omitted or left empty. ```lisp (defcfg) ``` -------------------------------- ### Basic Boolean Logic Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Demonstrates a basic boolean logic check using AND and OR operators. ```Kanata Logic (a && b && (c || d) && (e || f)) ``` -------------------------------- ### Simulated Input Tool Usage Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Example command to run the kanata_simulated_input tool with a configuration file and an input sequence file. This helps test keyboard configurations. ```bash kanata_simulated_input -c sim.kbd -s sim.txt ``` -------------------------------- ### Case 2 and 3 Logic Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Illustrates 'fallthrough' and 'break' behavior in Kanata logic checks. ```Kanata Logic (a b c) c fallthrough () b break ``` -------------------------------- ### Example Usage of Variables Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Demonstrates the practical application of `defvar` by defining variables for timeouts and then using them within `defalias` to create tap-hold actions. This promotes code reuse and readability. ```lisp (defvar tap-repress-timeout 100 hold-timeout 200 tt $tap-repress-timeout ht $hold-timeout ) (defalias th1 (tap-hold $tt $ht caps lctl) th2 (tap-hold $tt $ht spc lsft) ) ``` -------------------------------- ### Layer Check Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Demonstrates using the 'layer' list item to check if a specific layer is currently active. ```Kanata Lisp (defalias switch-layer-example (switch ((layer base)) x break ((layer other)) y break () z break ) ) ``` -------------------------------- ### Conditional Template Expansion with if-equal and versioning Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc This example shows how to use `if-equal` within a template to conditionally define key behavior based on a version string. It demonstrates expanding the template with different versions to achieve different results. ```lisp (deftemplate home-row (version) a s d f g h (if-equal $version v1 j) (if-equal $version v2 (tap-hold 200 200 j lctl)) k l ; ' ) (defsrc grv 1 2 3 4 5 6 7 8 9 0 - = bspc tab q w e r t y u i o p [ ] \ caps (template-expand home-row v1) ret lsft z x c v b n m , . / rsft lctl lmet lalt spc ralt rmet rctl ) (deflayer base grv 1 2 3 4 5 6 7 8 9 0 - = bspc tab q w e r t y u i o p [ ] \ caps (template-expand home-row v2) ret lsft z x c v b n m , . / rsft lctl lmet lalt spc ralt rmet rctl ) ``` -------------------------------- ### Tap-Hold Release Workaround Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Shows how to release 'f24' within the same 'multi' action to prevent repeats when using multiple tap-hold actions with the 'f24' workaround. ```lisp (defvirtualkeys relf24 (release-key f24)) ... (multi f24 (tap-hold ...) (macro 5 (on-press tap-vkey relf24))) ``` -------------------------------- ### Tap-Hold-Release-Keys Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Configures a tap-hold action where pressing specific keys triggers an early tap. This variant operates on physical input keys. ```lisp (defalias ;; tap: u hold: misc layer early tap if any of: (a o e) are pressed umk (tap-hold-release-keys 200 200 u @msc (a o e)) ) ``` -------------------------------- ### Key History Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Demonstrates using key-history to check the recency of typed keys within a switch statement. ```Kanata Lisp (defalias swh (switch ((key-history a 1)) S-a break ((key-history b 1)) S-b break ((key-history c 1)) S-c break ((key-history d 8)) (macro d d d) break () XX break ) ) ``` -------------------------------- ### Basic Push Message Examples Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Demonstrates sending simple string messages and layer change notifications using the `push-msg` action. These can be used to signal events or states. ```kanata (defalias ;; Send a simple string message notify (push-msg "key-pressed") ;; Send layer change notification nav-on (push-msg "layer:nav:activated") nav-off (push-msg "layer:nav:deactivated") ) ``` -------------------------------- ### Run Kanata on macOS (with sudo) Source: https://github.com/jtroo/kanata/blob/main/README.md Builds and runs Kanata from source on macOS after installing the Karabiner driver. Requires sudo privileges to intercept keyboard input. ```bash git clone https://github.com/jtroo/kanata && cd kanata cargo build # --release optional, not really perf sensitive # sudo is needed to gain permission to intercept the keyboard sudo target/debug/kanata --cfg ``` -------------------------------- ### Define Virtual Keys for Modifier Actions Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc This example demonstrates defining virtual keys for common modifier actions like Control, Shift, Meta, and Alt. These virtual keys can then be activated using various actions within the configuration. ```lisp (defvirtualkeys ;; Define some virtual keys that perform modifier actions ctl lctl sft lsft met lmet alt lalt ) ``` -------------------------------- ### Simultaneous Key Press with Layer Activation Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Executes multiple actions simultaneously. This example holds the 'Alt' key while activating a layer, allowing for combined functionality. ```clojure (defalias atl (multi alt (layer-while-held alted-with-exceptions)) lft (multi (release-key alt) left) ;; release alt if held and also press left rgt (multi (release-key alt) rght) ;; release alt if held and also press rght ) (defsrc alt a s d f ) (deflayer base @atl _ _ _ _ ) (deflayer alted-with-exceptions _ _ _ @lft @rgt ) ``` -------------------------------- ### Minimal Kanata Configuration Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc A basic configuration demonstrating the use of `defsrc` and `deflayer` to remap keys. This example shows the fundamental structure for defining source and layer mappings. ```haskell (defsrc a b c) (deflayer start 1 2 3) ``` -------------------------------- ### Run Kanata Binary on macOS Source: https://github.com/jtroo/kanata/blob/main/docs/release-template.md This command makes the downloaded Kanata binary executable and then runs it with a specified configuration file. Ensure you have the correct driver installed and the binary is in your current directory or specified path. ```bash chmod +x kanata_macos_arm64 # may be downloaded without executable permissions sudo ./kanata_macos_arm64 --cfg ``` -------------------------------- ### Tap-Hold-Tap-Keys Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Configures a tap-hold action where pressing specific keys triggers an early tap, but pressing and releasing other keys does not. This variant operates on physical input keys and is useful for home row mods. ```lisp (defalias ;; tap: a hold: lsft early tap if any of: (s d f) are pressed ;; other keys do NOT trigger early hold ath (tap-hold-tap-keys 200 200 a lsft (s d f)) ) ``` -------------------------------- ### Define Configuration with Multiple Options Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Demonstrates how to use the `defcfg` entry to define multiple configuration options as key-value pairs. Options not applicable to the current operating system are ignored. ```lisp (defcfg a 1 b 2) ``` ```lisp ;; Don't actually use this exact configuration, ;; it's almost certainly not what you want. (defcfg process-unmapped-keys yes danger-enable-cmd yes sequence-timeout 2000 sequence-input-mode visible-backspaced sequence-backtrack-modcancel no log-layer-changes no delegate-to-first-layer yes movemouse-inherit-accel-state yes movemouse-smooth-diagonals yes dynamic-macro-max-presses 1000 linux-dev (/dev/input/dev1 /dev/input/dev2) linux-dev-names-include ("Name 1" "Name 2") linux-dev-names-exclude ("Name 3" "Name 4") linux-continue-if-no-devs-found yes linux-unicode-u-code v linux-unicode-termination space linux-x11-repeat-delay-rate 400,50 windows-altgr add-lctl-release windows-interception-mouse-hwid "70, 0, 60, 0" ) ``` -------------------------------- ### Tap-Hold-Tap-Keys-Release Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Configures a tap-hold action with two conditions for an eager tap: pressing specific keys, or pressing and then releasing other specific keys. This variant also operates on physical input keys. ```lisp (defalias ;; tap: u hold: misc layer early tap if any of: ;; (z x c v) are pressed, OR ;; (a s d f) are pressed THEN released umk2 (tap-hold-release-tap-keys-release 200 200 u @msc (z x c v) (a s d f)) ) ``` -------------------------------- ### Install Kanata using Cargo Source: https://github.com/jtroo/kanata/blob/main/README.md Installs Kanata globally using the Cargo package manager. This command is suitable for users who have Rust and Cargo set up. ```bash cargo install kanata ``` -------------------------------- ### Install with 'interception_driver' feature flag on Windows Source: https://github.com/jtroo/kanata/blob/main/README.md On Windows, use this command to install Kanata with the 'interception_driver' feature enabled. This flag is added using the --features argument. ```bash cargo install --features interception_driver ``` -------------------------------- ### Server Response: Hello (Version and Capabilities) Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Response to 'Hello'. Contains server version, protocol version, and supported capabilities, including 'hold-activated' and 'tap-activated'. ```json {"HelloOk":{"version":"1.11.0","protocol":1,"capabilities":[...]}} ``` -------------------------------- ### Manage OpenRC daemon service Source: https://github.com/jtroo/kanata/blob/main/docs/setup-linux.md Commands to make the Kanata OpenRC script executable, start the service, check its status, and add it to the default runlevel to start automatically at boot. ```bash sudo chmod +x /etc/init.d/kanata # script must be executable sudo rc-service kanata start rc-status # check that kanata isn't listed as [ crashed ] sudo rc-update add kanata default # start the service automatically at boot ``` -------------------------------- ### Manage systemd user services Source: https://github.com/jtroo/kanata/blob/main/docs/setup-linux.md Commands to reload systemd user configurations, enable the Kanata service to start on boot, and start the service immediately. Also includes a command to check the service status. ```bash systemctl --user daemon-reload systemctl --user enable kanata.service systemctl --user start kanata.service systemctl --user status kanata.service # check whether the service is running ``` -------------------------------- ### Uninstall VHID Daemon (DriverKit Only) Source: https://github.com/jtroo/kanata/blob/main/docs/setup-macos.md Removes the VHID daemon if it was installed separately for DriverKit usage. ```sh sudo launchctl bootout system/org.pqrs.Karabiner-VirtualHIDDevice-Daemon sudo rm /Library/LaunchDaemons/org.pqrs.Karabiner-VirtualHIDDevice-Daemon.plist ``` -------------------------------- ### NOT Operator Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Shows how to use the 'not' boolean operator to negate a set of conditions. ```Kanata Lisp (defalias swn (switch ((not x y z)) S-a break ;; the above and below cases are equivalent in logic ((not (or x y z))) S-a break ) ) ``` -------------------------------- ### Load Specific Configuration File by Path Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Loads a specific configuration file by its absolute path. ```json {"ReloadFile":{"path":"/path/to/config.kbd"}} ``` -------------------------------- ### Load Previous Configuration File Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Loads the previous configuration file in the list. This is equivalent to the 'lrpv' keyboard action. ```json {"ReloadPrev":{}} ``` -------------------------------- ### Conditional Alias Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Defines an alias that is only active when the environment variable 'LAPTOP' is set to 'lp1'. This is useful for device-specific configurations. ```kanata (defaliasenvcond (LAPTOP lp1) met @lp1met ) ``` -------------------------------- ### Load Next Configuration File Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Loads the next configuration file in the list. This is equivalent to the 'lrnx' keyboard action. ```json {"ReloadNext":{}} ``` -------------------------------- ### Show Help Text Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Displays help text for specific arguments like -h or --help and exits. ```bash # bash === Show help text: `-h`, `--help` Only show help text that describes these arguments, then exit the program. ``` -------------------------------- ### Define Input Devices with Vendor and Product IDs Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Maps arbitrary IDs to specific keyboards using their vendor and product IDs. Useful for differentiating between multiple keyboards with similar layouts. ```bash (defvar id-AppleInternal 1 id-Go60 2 ) (definputdevices $id-AppleInternal ((name "Apple Internal Keyboard")) $id-Go60 ((name "Go60") (vendor_id 0x1D50) (product_id 0x615E)) ) (defsrc a) (deflayer base (switch ((device-history $id-AppleInternal 1)) x break ((device-history $id-Go60 1)) y break () a break)) ``` -------------------------------- ### Sample Zippy File Content Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc This snippet demonstrates the content of a sample zippy file, mapping input chords to their corresponding outputs. ```bash dy day dy 1 Monday dy 2 Tuesday abc alphabet w a Washington gi git gi f p git fetch -p ``` -------------------------------- ### Build Kanata WASM for Web Source: https://github.com/jtroo/kanata/blob/main/wasm/README.md Generates WASM files for use in a web browser environment. Ensure you have the necessary Rust targets and wasm-bindgen installed. ```bash wasm-pack build --target web ``` -------------------------------- ### Load Configuration by Index Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Loads a configuration file at a specific index (0-based) in the list. ```json {"ReloadNum":{"index":0}} ``` -------------------------------- ### Input History Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Illustrates using input-history to check the recency of inputs within a switch statement, noting recency differences from key-history. ```Kanata Lisp (defalias switch-input-history-example (switch ((input-history real lsft 2)) $var1 break ((input-history virtual vk2 2)) $var1 break () $ac3 break ) ) ``` -------------------------------- ### Execute Alias on Configuration Load Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Selects an alias to run when Kanata starts or after a live reload. Can be used to execute external commands or manage layers. ```lisp (defcfg alias-to-trigger-on-load S danger-enable-cmd yes ) (deffakekeys B (layer-while-held block)) (defalias P (on-press toggle-vkey B) S (macro @P (cmd beep)) ) (defsrc i o p ) (deflayer base o i @P ) (deflayer block • • _ ) ``` -------------------------------- ### Sample Kanata Zippychord Configuration Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc This snippet shows a sample configuration for zippychord, including settings for deadlines, idle times, and character mappings. ```bash (defzippy zippy.txt on-first-press-chord-deadline 500 idle-reactivate-time 500 smart-space-punctuation (? ! . , ; :) output-character-mappings ( ;; This should work for US international. ! S-1 ? S-/ % S-5 "(" S-9 ")" S-0 : S-; < S-, > S-. r#"# S-' | S-\ _ S-- ® AG-r ’ (no-erase `) é (single-output ' e) ) ) ``` -------------------------------- ### Load uinput kernel module on Linux Source: https://github.com/jtroo/kanata/wiki/Avoid-using-sudo-on-Linux Manually load the 'uinput' kernel module. This command might be necessary each time Kanata is started for the first time. ```bash sudo modprobe uinput ``` -------------------------------- ### Activate Karabiner DriverKit and Approve System Extension Source: https://github.com/jtroo/kanata/blob/main/docs/setup-macos.md Activate the Karabiner-DriverKit-VirtualHIDDevice and approve its system extension through System Settings. A reboot might be necessary if the driver was previously deactivated. ```sh sudo /Applications/.Karabiner-VirtualHIDDevice-Manager.app/Contents/MacOS/Karabiner-VirtualHIDDevice-Manager forceActivate ``` -------------------------------- ### Help Text Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Displays help text for command-line arguments. ```APIDOC ## Show help text: `-h`, `--help` Only show help text that describes these arguments, then exit the program. ``` -------------------------------- ### Zippychord Output Character Mappings (Special Characters) Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Configures the output for special Lisp syntax characters within the Zippychord configuration. Examples provided for US layout. ```lisp ")" $right-paren-output "(" $left-paren-output r#"""# $double-quote-output ``` ```lisp ")" S-0 "(" S-9 r#"""# S-' ``` -------------------------------- ### Continue if No Devices Found on Linux Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Set `linux-continue-if-no-devs-found` to `yes` to prevent Kanata from crashing when no input devices are detected on Linux. ```bash (defcfg linux-continue-if-no-devs-found yes ) ``` -------------------------------- ### Platform-Specific Configuration Syntax Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Define configurations that are active only for specific operating systems. Use the 'platform' keyword followed by applicable platforms and the configuration block. ```lisp (platform (applicable-platforms) ...) ``` -------------------------------- ### Tap-Hold-Except-Keys Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Configures a tap-hold action where pressing specific keys always triggers a tap, regardless of hold timeout. This variant operates on physical input keys. ```lisp (defalias ;; tap: u hold: misc layer always tap if any of: (a o e) are pressed umk (tap-hold-except-keys 200 200 u @msc (a o e)) ) ``` -------------------------------- ### Configure Mouse Movement Key and Key Bindings Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc This snippet shows how to enable mouse movement events by defining a mouse movement key and setting up key bindings for layers and aliases. ```bash (defcfg process-unmapped-keys yes mouse-movement-key mvmt ) (defsrc k l ; mvmt ) (defvirtualkeys mouse (layer-while-held mouse-layer) ) (defalias mhld (hold-for-duration 750 mouse) ) (deflayer qwerty k l ; @mhld ) (deflayer mouse-layer mlft mmid mrgt @mhld ) ``` -------------------------------- ### Batch file content for starting Kanata Source: https://github.com/jtroo/kanata/wiki/Toolbar-shortcut-for-Windows-10 This batch script executes the Kanata application with a specified configuration file. Replace `` with your actual configuration file name. ```batch kanata.exe --cfg ``` -------------------------------- ### Create uinput group on Linux Source: https://github.com/jtroo/kanata/wiki/Avoid-using-sudo-on-Linux Use this command if the 'uinput' group does not already exist on your Linux system. ```bash sudo groupadd uinput ``` -------------------------------- ### Tap-Hold Action Example Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Defines aliases for tap-hold actions, specifying tap and hold behaviors for keys 'a', 'o', and 'e'. The tap repress timeout is 200ms, and the hold timeout is 200ms. ```kanata (defalias anm (tap-hold 200 200 a @num) ;; tap: a hold: numbers layer oar (tap-hold-press 200 200 o @arr) ;; tap: o hold: arrows layer ech (tap-hold-release 200 200 e @chr) ;; tap: e hold: chords layer ) ``` -------------------------------- ### Set Linux Device Grab Delay Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc On Linux, use `-w` or `--wait-device-ms` to introduce a delay in milliseconds before attempting to grab devices. This helps mitigate issues with devices that take time to become ready. ```bash kanata -w 500 ``` ```bash kanata --wait-device-ms 500 ``` -------------------------------- ### Example: Map Caps Lock to Escape using Deflayermap Source: https://github.com/jtroo/kanata/blob/main/docs/config.adoc Demonstrates mapping the Caps Lock key to the Escape action using deflayermap. This requires a defsrc definition to be present. ```kanata ;; defsrc is still necessary (defsrc) (deflayermap (base-layer) caps esc) ``` -------------------------------- ### Build with combined feature flags Source: https://github.com/jtroo/kanata/blob/main/README.md To combine multiple feature flags, use a single --features argument with features separated by commas. This example enables both 'cmd' and 'interception_driver'. ```bash cargo build --release --features cmd,interception_driver ```