RJ Systems
Linux System Administration
Home Tech Linux Links Consulting

Valid XHTML 1.0!

Valid CSS!

IPv6 test

Configuring hotkeys for the console

There are two types of hotkeys to create in Linux: console hotkeys and X hotkeys. This explains how to configure console hotkeys on a Debian Linux system.

1. Making hotkeys on the Linux console

There are three things you have to do to make a console hotkey:

  1. Create a readline configuration file. If intended to be system-wide, use /etc/inputrc, but if only meant for private consumption, use ~/.inputrc.
  2. Make en environment variable called INPUTRC that points to either of the files mentioned above.
  3. Determine the sequence of characters that is generated by the desired key(-combination).
  4. Configure the readline configuration file.

The first two steps are self-explanatory, so I'll only explain the last two below, which are not so obvious.

2. Key-character sequences

Depending on your terminal type, sequences of key-characters are sent to readline for interpretation. It is these key-character sequences that you want your system to react differently to. But, first you have to find out what they key-character sequence is of the key that you want to configure as a hotkey. To find that out, you use readline's quoted-insert function, which you should find bound to Ctrl-v. It works like this (at the console):

~$ [Ctrl-v] [key(-combination)]

For example, pressing Ctrl-v followed by F10 produces: ^[[21~

3. Configuring readline

More is possible, but the simplest syntax for readline looks like this:

"[key-character sequence]": "[command]"

So, for example, to get Midnight Commander (mc) to start up when F10 is pressed, add the following line to the readline configuration file:

"\e[21~": "mc"

However, in this case hitting F10 would only result in 'mc' showing up on the command line; you'd still have to press Enter to get mc to actually start. To make F10 do mc [ENTER], modify the line as follows:

"\e[21~": "mc\C-M"

The Carriage Return is also known as a Control-M, which is what readline's special notation "\C-M" represents.

4. Sources:

Last modified: 2010-04-22, 17:36

©2003-2014 RJ Systems. Permission is granted to copy, distribute and/or modify the
content of this page under the terms of the OpenContent License, version 1.0.