Linux: Keyboard Software Guide

By Xah Lee. Date: . Last updated: .

This page is a overview of how to create keyboard shortcuts, how to remap/swap keys, how to change keyboard layout.

Get a Programable Keyboard

The best solution is to get a programable keyboard, especially on linux.

Overview of Linux Key Programing

In Linux, there are 2 steps to create keyboard shortcuts:

  1. Action: A shell command that does something, for example, switch/close window, simulate key press, mouse click, launch app, open file, empty trash.
  2. Bind Key: Make a key press run a shell command/script.

Keybinding Using System Settings Graphical User Interface App

The most easy way to add a new keyboard shortcut or keyboard layout, is the system control panel in a graphical user interface (available in any of the Gnome, KDE, Ubuntu, Xfce, LXDE). Under the system control panel (aka Setting Manager or System Preference), usually there are apps named Window Manager, or Keyboard, or Keyboard Layout.

xfce window manager keys setup  2013-06-07
xfce window manager keys setup

The window manager typically lets you set keys related to manipulating windows, such as {switch, close, max/min, move, show/hide/iconify}, or switch workspace (aka virtual screen), etc.

xfce keyboard setting panel 2013-06-01
xfce keyboard setting panel

The keyboard setting tool typically lets you set a key to launch app, or run a shell script. But it cannot swap keys nor set a key to send key combo such as Ctrl+s.

Swapping Keys, Remap Keys

xmodmap

xmodmap is a simple tool that lets you remap/swap keys for apps running under X11.

Linux: xmodmap Tutorial

Scancode, Keycode, Keysym

To work with keys in Linux X11, you must understand {scancode, keycode, keysym} because many key tools use their concept and syntax.

Scancode
A number your keyboard send to computer. For USB keyboards, it's defined by the USB standard.
Keycode
A number used by Linux kernel to represent key (or mouse button/wheel). The Linux kernel translates scancode to keycode.
Keysym
(key symbol) A short descriptive string to represent key, received by X11 applications.

How to find the scancode of a key?

[see Linux: Find Keyboard Key Scancode]

How to find the keycode / keysym of a key?

[see Linux: X11 Keyboard Key Names]

How to set system keyboard layout?

Keybinding in linux can be divided into 2 layers: the X11 window system layer, or system level.

Many keybinding setup works in X11 only. For example, when in Linux Virtual Console or single user mode console or system startup console, your custome key setting won't kick in.

The letter layout, is usually in the system layer. (but it can also be X11 layer only too.)

[see Linux: Set System Keyboard Layout]

Tool to Bind Key

xbindkeys

If your desktop doesn't have a graphical user interface settings app to bind a key to launch a script, then you can use xbindkeys.

[see Linux: xbindkeys Tutorial]

Tool for Key Actions

wmctrl for Switch Windows

wmctrl is a command line tool to {switch, close, move, resize, set title, list, …} windows.

Linux: Add Keyboard Shortcut to Switch App

xvkbd for Sending Keychords

xvkbd is a virtual keyboard for X window system. It is useful as a shell command to send keys.

Linux: xvkbd tutorial

Linux: Control Sound Level by Command Line

Linux: Change Volume by Command

xdotool

xdotool. «programatically simulate keyboard input and mouse activity. It does this using X11's XTEST extension and other Xlib functions.»

(note: i tried xdotool under Ubuntu/xfce. Doesn't work in my first 30 min of looking into it.)

#Install xdotool
 sudo apt-get install xdotool

Example. Send Ctrl+w to close tab.

xdotool key --delay 40 Control_L+w

Example. Click on upper left corner, (90, 10) pixels.

xdotool mousemove 90 10 click 1

ydotool

“Generic Linux command-line automation tool (no X!)”

https://github.com/ReimuNotMoe/ydotool

(2021-02-16 note: i haven't used ydotool.)

AutoKey

AutoKey

(2021-02-16 note: i haven't used AutoKey.)

Other Keyboard Tools

xkeysnail

This is new around 2015. I never tried. https://github.com/mooz/xkeysnail

Customize Mouse Buttons (IMWheel)

https://wiki.archlinux.org/index.php/IMWheel

Emacs

Emacs Keys

Space Bar as Dual Key (xcape)

Linux utility to configure modifier keys to act as other keys when pressed and released on their own. https://github.com/alols/xcape

Linux Keybinding Howto

Mouse

Linux Desktop keys