(defcfg ;; For Linux input (device-file "/dev/input/by-id/usb-HyperX_Alloy_Elite_RGB_HyperX_Alloy_Elite_RGB-event-kbd") output (uinput-sink "My KMonad output" ;; To understand the importance of the following line, see the section on ;; Compose-key sequences at the near-bottom of this file. "sleep 1 && setxkbmap -option compose:ralt") cmp-seq ralt ;; Set the compose key to `RightAlt' cmp-seq-delay 5 ;; 5ms delay between each compose-key sequence press key-seq-delay 5 ;; 5ms delay between each outputted key event ;; For Windows ;; input (low-level-hook) ;; output (send-event-sink) ;; For MacOS ;; input (iokit-name "my-keyboard-product-string") ;; output (kext) ;; Comment this if you want unhandled events not to be emitted fallthrough true ;; Set this to false to disable any command-execution in KMonad allow-cmd true ;; Set the implicit around to `around` implicit-around around ) #| -------------------------------------------------------------------------- Necessary: at least 1 `defsrc` block It is difficult to explain the `defsrc` block without immediately going into `deflayer` blocks as well. Essentially, KMonad maps input-events to various internal actions, many of which generate output events. The `defsrc` block explains the layout on which we specify our `deflayer`s down the line. It is important to realize that the `defsrc` block doesn't *necessarily* have to coincide with your actual input keyboard. You can specify a full 100% `defsrc` block, but only use a 40% keyboard. This will mean that every `deflayer` you specify will also have to match your 100% `defsrc`, and that your actual keyboard would be physically unable to trigger about 60% of your keymap, but it would be perfectly valid syntax. The dual of this (and more useful) is that it is also perfectly valid to only specify that part of your keyboard in `defsrc` that you want to remap. If you use a 100% keyboard, but don't want to remap the numpad at all you can simply leave the numpad out of your `defsrc`, and it should work just fine. In that particular case you probably want to set `fallthrough` to `true` in your `defcfg` block though. There is also support for named `defsrc` blocks. They contain `:name ` as the first argument in their definition. The layouting in the `defsrc` block is completely free, whitespace simply gets ignored. We strive to provide a name for every keycode that is no longer than 4 characters, so we find that laying out your keymap in columns of 5 works out quite nicely (although wider columns will allow for more informative aliases, see below). You can also insert a placeholder button using `XX`. This is almost the same as extra white space but you still need to bind a button to it. Said button is never used. This is occasionally useful if you have buttons which don't emit a keycode or have the same keycode multiple times on the same keyboard. In such cases large chunks of whitespace may be more confusing then a placeholder button. If you further want to specify which button this placeholder refers to, you can use an alias (see below). Instead of keycodes directly you can also use an alias (see `defalias`). The syntax for aliases is the same as described in `deflayer`. Keep in mind that buttons, which won't work if you place them in `defsrc` directly, will also not work if you use them via an alias. Most keycodes should be obvious. If you are unsure, check './src/KMonad/Keyboard/Keycode.hs'. Every Keycode has a name corresponding to its Keycode name, but all lower-case and with the 'Key' prefix removed. There are also various aliases for Keycodes starting around line 350. If you are trying to bind a key and there is not a 4-letter alias, please file an issue, or better yet, a pull-request, and it will be added promptly. Also, you can consult './keymap/template/' for various input templates to use directly or to look up keycodes by position. Here we use the input-template for 'us_ansi_60.kbd' -------------------------------------------------------------------------- |# (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 cmp rctl ) (deflayer capsasa grv 1 2 3 4 5 6 7 8 9 0 - = bspc tab q w e r t y u i o p [ ] \ lctrl 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 cmp rctl ) (defsrc :name numpad nlck kp/ kp* kp- kp7 kp8 kp9 kp+ kp4 kp5 kp6 kp1 kp2 kp3 kprt kp0 kp. ) (defsrc :name with-aliases @foo @power) (defalias num (layer-toggle numbers) ;; Bind num to a button that switches to a layer kil C-A-del ;; Bind kil to a button that Ctrl-Alt-deletes power XX ;; Placeholder for power button of keyboard foo @bar ;; An alias with a forward reference to another alias bar a ) #| NOTE: The above code could just as easily have been written as: (defalias num (layer-toggle numbers)) (defalias kil C-A-del) (deflayer qwerty 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 @num lalt spc ralt rmet @sym @tst ) (deflayer phone :source numpad :implicit-around disabled nlck kp/ kp* kp- kp1 kp2 kp3 kp+ kp4 kp5 kp6 kp7 kp8 kp9 kprt kp0 kp. ) (deflayer numbers _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ XX / 7 8 9 - _ _ _ _ _ _ _ _ XX * 4 5 6 + _ _ _ _ \( \) . XX 0 1 2 3 _ _ _ _ _ _ _ _ _ _ ) (defalias ;; Something useful cpy C-c pst C-v cut C-x ;; Something silly md1 (around a (around b c)) ;; abc md2 (around a (around-only lsft b)) ;; aB md3 C-A-M-S-l md4 (around % b) ;; BEWARE: %B, not %b, do you see why? md5 (around-when-alone lctl c) ) (defalias ctl-lck (stepped (press-only lctl) (release-only lctl))) (deflayer modded-test _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @md4 _ _ _ _ _ _ _ _ _ _ _ _ _ @md1 @md2 @md3 _ _ _ _ _ _ _ _ _ _ @cut @cpy @pst _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ) (defalias mc1 #(K M o n a d) mc2 #(C-c P50 A-tab P50 C-v) ;; Careful, this might do something mc3 #(P200 h P150 4 P100 > < P50 > < P20 0 r z 1 ! 1 ! !) mc4 (tap-macro a (pause 50) @md2 (pause 50) c) mc5 (tap-macro-release esc esc esc) mc6 #(@mc3 spc @mc3 spc @mc3) ) (deflayer macro-test _ @mc1 @mc2 @mc3 @mc4 @mc5 @mc6 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ )