Skip to content

Setting custom keybindings

Eduardo edited this page Jun 3, 2021 · 3 revisions

Custom keybindings are necessary if you want the best workflow possible for SRS card creation. Running your scripts with a few keypresses is what makes them so convenient and productive.

In other to map certain key combinations to the execution of scripts, one may use different methods at their disposal, such as the interface provided by the desktop environment, the window manager or a specific application for that purpose, called hotkey daemon.

Desktop Environment

Most desktop enviroments (DEs) come with a keybinding program. For example:

  • on XFCE4, go to Settings → Keyboard → Application Shortcuts
  • on GNOME, go to Settings → Keyboard Shortcuts.
  • on KDE, go to Shortcuts and Gestures → Custom Shortcuts → Edit → New → Global Shortcut → Command/URL

Make sure to check your DE's documentation.

Window Manager

If you don't use a desktop environment, you may need to set custom keybindings within your Window Manager (WM). Again, most WMs support that and you should check the documentation for your WM. There might be the need to edit a configuration file or the source code, in which case you'd have to recompile the WM.

Hotkey Daemon

Another option is to set up a hotkey daemon and have your configuration independent of DEs or WMs. Simple X Hotkey Daemon (sxhkd) is a very small software that uses a simple text file as configuration as is available on most distribution's package managers.

Here's a sample configuration file located at ~/.config/sxhkd/sxhkdrc.

mod4 + F5
 record

mod4 + F6
 /usr/lib/mozc/mozc_tool --mode=hand_writing

Print
 printscreen -r

alt + Print
 printscreen -f

shift + Print
 printscreen

mod4 + Print
 ocrshot

ctrl + Print
 ocrshot -H

You can define key combinations in one line and, on the next line, add a whitespace character followed by the command. All sorts of keys and modifiers are available like shift, ctrl, alt, super, etc. Read the respective man page.

After setting up your keys, run the command sxhkd and fork it to the background.

$ sxhkd &

Now you should have you custom keybindigs enabled.

It's a good idea to launch and fork it when starting a X section, so add that line to your .xinitrc.

~/.xinitrc
----------

...
sxhkd &
...

If you change the file .sxhkdrc, you can reload the configuration by sending the signal SIGUSR1 to sxhkd.

$ pkill --signal SIGUSR1 sxhkd

Clone this wiki locally