keyd Documentation

repository·master·Indexed 26 days ago

https://github.com/rvaiya/keyd

A system-wide, high-performance keyboard remapping daemon for Linux. It utilizes kernel-level input primitives (evdev, uinput) to provide flexible key remapping, layers, and key overloading independently of the display server. Features include application-specific remapping via keyd-application-mapper, macro support, and the ability to act as a USB HID gadget for USB-to-USB conversion.

Tokens
1.7K
Snippets
6
Records
13
Agent score
91%

What's inside keyd

  1. Quickstart: Configure keyd for basic remapping

    master

    To set up a basic configuration (e.g., mapping Caps Lock to Escape on tap and Control on hold):

    1. Ensure keyd is installed and running (sudo systemctl enable --now keyd).
    2. Create or edit /etc/keyd/default.conf.
    3. Add your configuration rules.
    4. Reload the configuration to apply changes.

    You can use keyd monitor to find the exact names of your keys. Note that while keyd is running, keyd monitor shows the output of keyd; to see original hardware events, stop keyd first.

    Note: If you use a mouse that emits keys (like Logitech MX Master), you may need to explicitly blacklist its ID in the [ids] section to prevent it from being caught by the wildcard *.

    [ids]
    
    *
    
    [main]
    
    # Maps capslock to escape when pressed and control when held.
    capslock = overload(control, esc)
    
    # Remaps the escape key to capslock
    esc = capslock
  2. Configure application-specific remapping

    master

    keyd supports experimental application-specific remapping (e.g., different shortcuts for Alacritty or Chromium).

    1. Add your user to the keyd group: usermod -aG keyd <user>
    2. Create a configuration file at ~/.config/keyd/app.conf.
    3. Define mappings using the application name as the section header.
    4. Run the keyd-application-mapper daemon.

    Integration: For non-Gnome environments, you should add keyd-application-mapper -d to your display server initialization (e.g., ~/.xinitrc).

    usermod -aG keyd <user>
    
    # Example ~/.config/keyd/app.conf content:
    [alacritty]
    alt.] = macro(C-g n)
    alt.[ = macro(C-g p)
    
    [chromium]
    alt.[ = C-S-tab
    alt.] = macro(C-tab)
    
    # Run the mapper
    keyd-application-mapper
  3. Configure keyd as a USB HID gadget

    master
    On Linux devices equipped with both a USB host port and a USB OTG or device port, you can use keyd to act as a USB-to-USB converter board. In this configuration, a keyboard is connected to the host port, and the Linux device is connected to a PC via the OTG/device port. keyd translates evdev input events from the keyboard into HID reports sent via the Linux USB HID gadget driver.
  4. Install keyd with USB HID gadget support

    master

    To build and install keyd with the usb-gadget virtual keyboard driver (VKBD) enabled, follow these steps. This requires building from source using the VKBD=usb-gadget flag.

    After installation, you must enable and start both the keyd-usb-gadget service and the standard keyd service.

    git clone https://github.com/rvaiya/keyd
    cd keyd
    make VKBD=usb-gadget && sudo make install VKBD=usb-gadget
    sudo systemctl enable keyd-usb-gadget && sudo systemctl start keyd-usb-gadget
    sudo systemctl enable keyd && sudo systemctl start keyd
  5. Install keyd from source

    master

    To install keyd from source, you need a C compiler and Linux kernel headers. Follow these steps:

    1. Clone the repository.
    2. Build and install using make.
    3. Enable and start the keyd systemd service.

    Warning: A bad configuration file can make your machine unusable. If this happens, press the special key sequence backspace+escape+enter to terminate keyd immediately.

    git clone https://github.com/rvaiya/keyd
    cd keyd
    make && sudo make install
    sudo systemctl enable --now keyd
  6. Define custom modifier layers

    master
    Modifier sequences (like C-M) are no longer valid layers by default. To achieve the effect of a layer that requires specific modifiers, you must explicitly define an empty layer with those modifier tags. Note that full modifier names (like meta) are automatically mapped to layers with the same name, so you do not need to define them explicitly.
  7. Install keyd via package managers

    master

    keyd is available in several official and community repositories:

    • Debian 13+ / Ubuntu 25.04+: sudo apt install keyd (For older Ubuntu, use ppa:keyd-team/ppa)
    • openSUSE: sudo zypper in keyd
    • Void Linux: sudo xbps-install -Su keyd
    • Arch Linux: Available in extra repository.
    • Alpine Linux: Available via apk.
    • Fedora: Available via COPR.
    • Gentoo: Available via GURU.
  8. Configure transparent layers and modifiers in v2.3.0-rc+

    master

    In version 2.3.0-rc and later, layers are fully transparent. Bindings are resolved based on activation order, with [main] being the default active layer.

    Modifiers apply to all bindings except for those associated with the active layer. This allows you to pair modifiers with layer entries without needing complex layer nesting. For example, if a layer is activated via a key, modifiers applied to that key will not affect the bindings within that layer, but modifiers applied externally will.

  9. Verify USB HID gadget installation

    master
    Once installed and running, the device should appear on the host machine as 1d6b:0104 Linux Foundation Multifunction Composite Gadget. You can verify the gadget is active by checking the output of lsof or looking for the device node at /dev/input/by-id/Tux_USB_Gadget_Keyboard.
  10. Manage keyd daemon and reloading

    master

    The following management features have been removed in recent versions:

    • The -d flag (daemonization) has been eliminated; use your init system to manage the daemon.
    • reload on SIGUSR1 has been eliminated; perform a full restart of the service instead.
  11. Fix trackpad interference with libinput

    master

    Because keyd creates a virtual device that combines internal and external keyboards, libinput's 'disable-while-typing' feature may fail to distinguish them, causing trackpad issues.

    To fix this, tell libinput to treat the keyd virtual device as internal by creating or editing /etc/libinput/local-overrides.quirks with the following content:

    [Serial Keyboards]
    
    MatchUdevType=keyboard
    MatchName=keyd*keyboard
    AttrKeyboardIntegration=internal
  12. Use macros and escape special characters

    master
    Sequences have been replaced by macros. Actions that previously accepted sequences as a second argument now accept macros of any kind. When defining macros, certain special characters such as ) and \ must be escaped with a backslash.