The Simple X Hotkey Daemon (sxhkd) is a small program that is a large part of the reason that Linux is one of the best operating systems for those with forms of RSI that makes computer use difficult. It began life as a lightweight way to add keybindings to the ultra minimalist tiling window manager, bspwm. It also gained traction among users of the equally minimalist floating window manager, Oroborus. The initial design for sxhkd was to allow traditional keyboard shortcuts such as Control+Q to close a program, which is what most Linux desktop systems such as Gnome and KDE offer, and the same goes for Microsoft Windows. However in response to online requests the creator of sxhkd added the ability to set up key chains, where no more than one key is pressed at a time. Few Linux window managers allow such key chains, with the main exceptions being Fluxbox and Openbox, while FVWM can provide the equivalent via its menu system.
The basic functionality is that it allows the user to set hotkeys to operate commands that can be invoked from the command-line. If a particular window manager does not have a system for allowing control from the command-line then sxhkd cannot control that directly, but there is a workaround. By using sxhkd to invoke another program such as xdotool it is possible to use sxhkd key chains to invoke the key chords necessary to operate window managers. The simplest way to use sxhkd is to use it to invoke programs, e.g., type F9 e m a c s to run the text editor Emacs. It cannot, however, be used directly to trigger commands within other programs. However again xdotool can be used, but it is more difficult to set up for specific programs, rather than globally. Therefore the best solution, where it is available, is to use sxhkd only where chain keys are not available within the window manager or program.
The default location for the sxhkd configuration is a file called sxhkdrc in a folder called sxhkd in the user's .config folder. So far so simple and its gets simpler. The configuration file is, as is the norm in Linux, a plain text file. Its configuration requires no special keywords to remember, except that a key chain has a semicolon after key. Alternatively, you can place a colon after the initial key and then a space between the subsequent keys. Each keybinding is set up by an initial line not beginning with a space that contains the keybinding and a second line beginning with at least one space that contains the command to be carried out when that key sequence is typed out. So to create a configuration file only including the above Emacs example you would write:
F9 : e m a c s
It is not necessary for the command line to begin with so many spaces, but it helps when looking at a long list of bindings. In general it is not a good idea to spell out the program name, even if it is easier to remember. If you want to spell out the full name it is better to use the window manager's method for running commands or a program like fbrun. When choosing the keys to put into the chain it is important to understand how sxhkd works. Once the opening key for a key chain is pressed sxhkd takes control of the keyboard and only surrenders that control if you complete a chain or take too long to type the next letter. Due to that taking control mechanism it is advisable to keep to just one or two opening keys (F9 in the above example). The opening key should be one that is generally not needed otherwise. It would be problematic to include a letter key as that would introduce a delay into your typing as sxhkd would briefly seize control of your keyboard every time that letter was typed. Also be aware of keys that the window manager or desktop environment is already using. The above example of F9 would not work in an unaltered Gnome environment (the most widely used desktop environment in Linux) as it defaults to having the F9 key trigger taking a photograph of your screen. Another key to avoid is Super_L (usually the Windows logo key) because it is used in several window managers and this will usually stop those sxhkd key chains from working.
A limitation caused by the way that sxhkd works is that you cannot have a keybinding that begins with the keys of a shorter binding. E.g., if you have configured sxhkd as
F9 : e
F9 : e m a c s
the emacs key chain will never work as xfe will open after you press the second key. If you can cope with remembering a lot of shortcuts it is best to have your most commonly used commands as two key chains and to group similar commands (e.g., different web browsers) as three key chains under a common second key. So this might give you:
F9 : a
F9 : b c
F9 : b f
F9 : b m
F9 : f
F9 : m
Other software gets around the problem of longer key chains being overridden by similar shorter chains by forcing the system to wait to see if a further key will be pressed. The failure of sxhkd to implement such a waiting system has the advantage that programs launch without a delay.
A major disadvantage of sxhkd is that you can end up with a lot of key chains to remember. Menu systems such as dmenu or the in-built menu system in FVWM have the advantage that you can see the option. A way to avoid complex key chains is to create a key that spells out the name of the program, but that gets a bit tedious with long names like
F9 : s q l i t e b r o w s e r
The best use for sxhkd is to compensate for those window managers that lack the ability to create chains. For example, i3 is a great window manager that can be controlled entirely by keyboard, but it is let down by its inability to create key chains. For RSI sufferers who struggle with key chords (e.g., Control+F) sxhkd can provide a way to continue using i3. For launching programs most users will probably find menu based solutions more convenient.