3 Home
dxtr edited this page 2026-10-17 04:51:55 +02:00

cl-xkbcommon

Keyboards for Common Lisp, through libxkbcommon. cl-xkbcommon compiles a keymap and follows the keys pressed. From those it tells you the symbols and text the keys produce, which modifiers are held, and what compose sequences such as dead keys produce.

It knows nothing about window systems. It takes keycodes and modifier masks, wherever they come from: Wayland, X11, evdev, or a test.

(asdf:load-system :cl-xkbcommon)

(defpackage #:example
  (:use #:cl)
  (:local-nicknames (#:xkb #:cl-xkbcommon)))
(in-package #:example)

(xkb:with-context (context)
  (xkb:with-keymap (keymap context :layout "se")
    (xkb:with-keyboard-state (state keymap)
      (list (xkb:key-press-text state nil 34)       ; the key right of P
            (progn (xkb:update-key state 50 :press) ; left Shift down
                   (list (xkb:active-modifiers state)
                         (xkb:key-press-text state nil 34)))))))
;; => ("å" ((:SHIFT) "Å"))

Pages

Start here

  • Getting Started: installing, loading, and a first program.
  • Concepts: keycodes, keysyms, layouts, levels and modifiers, and how they fit together.

Guides

  • Contexts and Keymaps: compiling keymaps from layout names or from text, and asking a keymap about its keys.
  • Keyboard States and Modifiers: following a keyboard, and reading keysyms, text and modifiers from it.
  • Keysyms: converting between keysyms, names and characters.
  • Compose and Dead Keys: turning sequences such as dead acute + e into é.
  • Recipes: text input, keyboard shortcuts, Wayland clients, evdev and key repeat.

Reference

Systems

System What it is
cl-xkbcommon The library. Use this one.
cl-xkbcommon/ffi Raw bindings to libxkbcommon, one Lisp function per C function.
cl-xkbcommon/test The Parachute test suite.

License

MIT.