Skip to content

Instantly share code, notes, and snippets.

@weeble
Created June 10, 2025 00:02
Show Gist options
  • Select an option

  • Save weeble/97e2be422f0b266a13e9e81e3482304c to your computer and use it in GitHub Desktop.

Select an option

Save weeble/97e2be422f0b266a13e9e81e3482304c to your computer and use it in GitHub Desktop.
Remapping caps-lock with kmonad
(defcfg
;; Of course we want fall-through. What would be the point of not having fall-through.
fallthrough true
;; JESUS CHRIST no. We are not having the keyboard directly executing commands.
allow-cmd false
;; This is the keyboard we're reading from...
input (device-file "/dev/input/by-id/usb-Apple_Inc._Apple_Internal_Keyboard___Trackpad_D3H5141GLZ1GHJGA71KF-if01-event-kbd")
;; And this is the virtual keyboard we're writing to. Name doesn't really matter.
output (uinput-sink "My KMonad output")
)
(defsrc
;; The keyboard before modification. Some keys (function keys, cursors, bspc) generate
;; different keycodes when fn is held, they're positioned close to the key. I think we
;; can actually turn off the special behaviour of the fn-key and take control of it
;; ourselves, using /sys/module/hid_apple/parameters/fnmode but let's worry about that
;; another day.
brdn brup scale dashboard bldn blup prev playpause next mute vold volu
esc f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 power
` 1 2 3 4 5 6 7 8 9 0 - = bspc del
tab q w e r t y u i o p [ ]
caps a s d f g h j k l ; ' \ ret
lsft 102d z x c v b n m , . / rsft
fn lctl lmet lalt spc rmet ralt left down up right
home pgdn pgup end
)
(defalias
;; Caps-escape acts as escape if tapped for <200ms, otherwise as a modifier to access the "holdcesc" layer.
cesc (tap-hold 200 esc (layer-toggle holdcesc))
)
;; Default key behaviours.
(deflayer default
brdn brup scale dashboard bldn blup prev playpause next mute vold volu
esc f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 power
` 1 2 3 4 5 6 7 8 9 0 - = bspc del
tab q w e r t y u i o p [ ]
@cesc a s d f g h j k l ; ' \ ret
lsft 102d z x c v b n m , . / rsft
fn lctl lmet lalt spc rmet ralt left down up right
home pgdn pgup end
)
;; Key behaviours when caps-escape is held. Underscores fall-through to the default layer.
(deflayer holdcesc
_ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _
esc _ _ _ _ _ _ _ _ _ _ _ _ del _
caps _ _ _ _ _ _ _ ins _ prnt _ _
_ _ _ _ _ _ left down up right _ _ _ _
_ _ C-z C-x C-c C-v _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _
_ _ _ _
)
@weeble

weeble commented Jun 10, 2025

Copy link
Copy Markdown
Author

I put this at /etc/kmonad/macbookpro.kbd and did

sudo systemctl start kmonad@macbookpro
sudo systemctl enable kmonad@macbookpro

This works because the Arch package has created /usr/lib/systemd/system/kmonad\@.service with this definition:

[Unit]
Description=KMonad keyboard config

[Service]
Restart=always
RestartSec=3
ExecStart=/usr/bin/kmonad %E/kmonad/%i.kbd
Nice=-20

[Install]
DefaultInstance=config
WantedBy=default.target

The %E means /etc and the %i means "whatever you put after kmonad@ when invoking systemctl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment