keyd(1) General Commands Manual keyd(1) NAME keyd - A key remapping daemon. SYNOPSIS keyd [command] [options] COMMANDS monitor [-t] Print key events. If -t is supplied, also prints time since the last event in ms. Useful for discovering key names/device ids and debugging. listen Print layer state changes of the running keyd daemon to stdout. Useful for scripting. bind reset| [...] Apply the supplied bindings. See Bindings for details. reload Reload config files. list-keys List valid key names. input [-t ] [...] Input the supplied text. If no arguments are given, read the input from STDIN. A timeout in microseconds may optionally be supplied corresponding to the time between emitted events. do [-t ] [] Execute the supplied expression. See MACROS for the format of . If no arguments are given, the expression is read from STDIN. If supplied, corresponds to the macro_sequence_timeout. OPTIONS -v, --version Print the current version and exit. -h, --help Print help and exit. DESCRIPTION keyd is a system wide key remapping daemon which supports features like layering, oneshot modifiers, and macros. In its most basic form it can be used to define a custom key layout that persists across display server boundaries (e.g wayland/X/tty). The program runs in the foreground, printing diagnostic information to the standard output streams, and is intended to be run as a single instance managed by the init system. NOTE: Because keyd modifies your primary input device, it is possible to render your machine unusable with a bad config file. If you find yourself in this situation the panic sequence ++ will force keyd to terminate. CONFIGURATION Configuration files loosely follow an INI style format consisting of headers of the form [section_name] followed by a set of bindings. Lines beginning with a hash are ignored. Config files are stored in /etc/keyd/ and loaded upon initialization. The reload command can be used to update the working set of config files (e.g sudo keyd reload). A valid config file has the extension .conf and must begin with an [ids] section that has one of the following forms: [ids] ... or [ids] * - - ... The first form specifies a list of ids to be explicitly matched, while the second matches any id which has not been explicitly excluded. For example: [ids] * -0123:4567 Will match all keyboards which do not(2) have the id 0123:4567, while: [ids] 0123:4567 will exclusively match any devices which do. Device ids can be obtained from the monitor command (see COMMANDS). Note that a device id may only be listed in a single config file. Each subsequent section of the file corresponds to a layer (with the exception of [global] (see GLOBALS). Config errors will appear in the log output and can be accessed in the usual way using your system's service manager (e.g sudo journalctl -eu keyd). If an id matches more than one device type, the prefix k: may be used to exclusively match keyboards and the prefix m: may be used to exclusively match mice. (E.g m:046d:b01d) Note: All keyboards defined within a given config file will share the same state. This is useful for linking separate input devices together (e.g foot pedals). Note 2: The wildcard will only match devices which keyd identifies as keyboards. keyd is also capable of managing mice (e.g to facilitate clearing of oneshot modifiers on click), but their ids must be explicitly listed. Note 3: Mouse support is currently experimental, and is mostly confined to traditional mice (e.g touchpads). Adding some mice to your ids section may break your pointer. It may also be necessary to explicitly blacklist mice which are misidentified as keyboards (e.g if you find your moused misbehaving). Layers A layer is a collection of bindings, each of which specifies the behaviour of a particular key. Multiple layers may be active at any given time, forming a stack of occluding keymaps consulted in activation order. The default layer is called main and is where common bindings should be defined. For example, the following config snippet defines a layer called nav and creates a toggle for it in the main layer: [main] capslock = layer(nav) [nav] h = left k = up j = down l = right When capslock is held, the nav layer occludes the main layer causing hjkl to function as the corresponding arrow keys. Unlike most other remapping tools, keyd provides first class support for modifiers. A layer name may optionally end with a ':' followed by a set of modifiers to emulate in the absence of an explicit mapping. Layer names may consist of a maximum of 64 characters (including all modifiers). These layers play nicely with other modifiers and preserve existing stacking semantics. For example: [main] capslock = layer(capslock) [capslock:C] j = down will cause capslock to behave as control, except in the case of capslock+j, which will emit down. This makes it trivial to define custom modifiers which don't interfere with one another. Note that bindings are not affected by the modifiers of the layer in which they are defined. Thus capslock+j will produce an unmodified down keypress, while shift+capslock+j will produce shift+down as expected. Formally, each layer heading has the following form: "[" [:] "]" Where has the form: [-]... and each modifier is one of: C - Control M - Meta/Super A - Alt S - Shift G - AltGr Finally, each layer heading is followed by a set of bindings which take the form: | = || for a description of and see ACTIONS and MACROS. By default, each key is bound to itself within the main layer. The exception to this are the modifier keys, which are instead bound to eponymously named layers with the corresponding modifiers. For example, meta is actually bound to layer(meta), where meta is internally defined as meta:M. The full set of modifier bindings are as follows: control = layer(control) meta = layer(meta) shift = layer(shift) leftalt = layer(alt) rightalt = layer(altgr) A consequence of this is that overriding modifier keys is a simple matter of adding the desired bindings to an appropriate pre-defined layer. Thus [ids] * [control] j = down is a completely valid config, which does what the benighted user might expect. Internally, the full config actually looks something like this: [ids] * [main] leftcontrol = layer(control) rightcontrol = layer(control) [control:C] j = down If multiple bindings for the same key are present, the most recent one takes precedence. A layer heading may also appear multiple times, in which case the layer will contain the sum of all bindings. Note that the layer type may not be reassigned. That is: [mylayer:A] a = b c = d [mylayer:C] a = x b = c is equivalent to: [mylayer:A] a = x b = c c = d Composite Layers A special kind of layer called a composite layer can be defined by creating a layer with a name consisting of existing layers delimited by +. The resultant layer will be activated and given precedence when all of its constituents are activated. Composite layers are not allowed to have modifiers attached and cannot be explicitly assigned. E.g. [control+alt] h = left will cause the sequence control+alt+h to produce left (ignoring the control and alt modifiers attached to the active control and alt layers), while pressing control+alt+f1 preserves those modifiers, emitting exactly what was pressed, as there is no explicit binding for f1 on the composite layer. [main] capslock = layer(capslock) [capslock:C] [capslock+shift] h = left Will cause the sequence capslock+shift+h to produce left, while preserving the expected functionality of capslock and shift in isolation. Note: composite layers must always be defined after the layers of which they are comprised. That is: [layer1] [layer2] [layer1+layer2] and not [layer1+layer2] [layer1] [layer2] Layouts A layout is a special kind of layer intended for modifying alpha keys. Unlike layers, layouts cannot have any associated modifiers, and only one layout may be active at a given time. The default layout is called 'main', and can be changed using the setlayout() action. For convenience, keyd ships with a number of common letter layouts in /usr/share/keyd/layouts. Before including these, it is instructive to inspect them. Non-english layouts include a dedicated shift layer (making order of inclusion important) and require the use of keyd's compose definitions (see Unicode Support) E.g. # Include the shipped colemak layout. include layouts/colemak [global] default_layout = mylayout [mylayout:layout] a = b b = c #etc... [control] 1 = setlayout(customlayout) 2 = setlayout(colemak) Chording Chords are groups of keys which are treated as a unit when simultaneously depressed. A chord can be defined by using a group of + delimited key names as a left hand value. The corresponding action will be activated if all keys are struck within the chording interval (chord_timeout). E.g j+k = esc will cause esc to be produced if both j and k are simultaneously depressed. Note: It may be desirable to change the default chording interval (50ms) to account for the physical characteristics of your keyboard. Unicode Support If keyd encounters a valid UTF8 sequence as a right hand value, it will try and translate that sequence into a macro which emits a keyd- specific XKB sequence. In order for this to work, the sequences defined in the compose file shipped with keyd (/usr/share/keyd/keyd.compose) must be accessible. This can be achieved globally by copying the file to the appropriate location in /usr/share/X11/locale, or on a per-user basis by symlinking it to ~/.XCompose. E.g. ln -s /usr/share/keyd/keyd.compose ~/.XCompose Additionally you will need to be using the default US layout on your display server. Users of non-english layouts are advised to set their layout within keyd (see Layouts) to avoid conflicts between the display server layout and keyd's unicode functionality. Note: You may have to restart your applications for this to take effect. Note 2: The generated compose sequences are affected by modifiers in the normal way. If you want shift to produce a different symbol, you will need to define a custom shift layer (see the included layout files for an example). Note 3: GTK4 currently has a bug which causes it to crash in the presence of large XCompose files (like /usr/share/keyd/keyd.compose). Aliases Each key may optionally be assigned an alias. This alias may be used in place of the key as a valid left hand value. Multiple keys may be bound to the same alias, but only one alias may be assigned to a key at a given time. For example, the keys 'leftmeta' and 'rightmeta' are bound to the alias meta by default. Thus the binding 'meta = a' is equivalent to the bindings 'leftmeta = a' and 'rightmeta = a'. Aliases are defined in a special section called 'aliases' where each line takes the form: = where must be a valid key name. Note that may itself be a valid key name, in which case all references to the key within the config file will be replaced with the new key. Additionally, if the assigned alias is a valid key name, the corresponding keycode will be assigned to the key by default. This makes it possible to redefine keys before any bindings are applied and is particularly useful in conjunction with the include mechanism to account for variations in hardware. For example: /etc/keyd/common: meta = oneshot(meta) alt = oneshot(alt) a = a s = o # etc.. /etc/keyd/default.conf: [ids] * [main] include common /etc/keyd/magic_keyboard.conf: [ids] 004c:0267 [aliases] leftalt = meta rightalt = meta rightmeta = alt leftmeta = alt [main] include common Allows the user to define a set of universal bindings in /etc/keyd/common without having to explicitly account for the transposed meta and alt keys within the included config snippet. File Inclusion Config files may include other files located within the config directory using the include keyword. A line of the form include may appear at any point after the [ids] section. The resultant config will behave as though the contents of the included file appear in place of the include statement. Making strategic use of these statements makes it possible to share common functionality between configs. Include paths are relative and must be placed in one of the following directories: o /etc/keyd/ o /usr/share/keyd/ E.g. /etc/keyd/default.conf: [ids] * # Add our shared custom bindings. include common # Appends bindings to the main layer # defined in /etc/keyd/common (order matters) [main] capslock = layer(capslock) [capslock] 1 = setlayout(colemak) 2 = setlayout(dvorak) /etc/keyd/common: [main] rightmeta = layer(nav) [nav] h = left j = down k = up l = right /usr/share/keyd/layouts/dvorak: a = a s = o ... Limitations: o All include statements should appear after the [ids] section in the including file. o Included files should not contain an ids section. o Included files should not include other files (inclusion is non-recursive). o Included files should not end in .conf. GLOBALS A special section called [global] may be defined in the file and can contain any of the following options: macro_timeout: The time (in milliseconds) separating the initial execution of a macro sequence and the first repetition. (default: 600) macro_repeat_timeout: The time separating successive executions of a macro. (default: 50) layer_indicator: If set, this will turn the capslock light on whenever a layer is active. Note: Some wayland compositors will aggressively toggle LED state rendering this option unusable. (default: 0) macro_sequence_timeout: If set, this will add a timeout (in microseconds) between each emitted key in a macro sequence. This is useful to avoid overflowing the input buffer on some systems. chord_timeout: The maximum time between successive keys interpreted as part of a chord. (default: 50) chord_hold_timeout: The length of time a chord must be held before being activated. (default: 0) oneshot_timeout: If non-zero, timeout a oneshot layer activation after the supplied number of milliseconds. (default: 0) disable_modifier_guard: By default, keyd will inject additional control keypresses where necessary in order to prevent programs from seeing additional modifier taps (E.g alt in firefox). If set, this option disables that behaviour. (default: 0) overload_tap_timeout: If non-zero, ignore the tap behaviour of an overloaded key if it is held for the given number of miliseconds. (default: 0). Note: Unicode characters and key sequences are treated as macros, and are consequently affected by the corresponding timeout options. MACROS Various keyd actions accept macro expressions. A macro expression has one of the following forms: 1. macro() 2. [[-...]- 3. Where is a valid unicode character and has the form [...] and each token is one of: o A valid key code. o A type 2 macro. o A contiguous group of unicode characters. o A group of key codes delimited by + to be depressed as a unit. o A timeout of the form