Consistent Keyboard Configuration
One of the convenient features of Linux is that the keyboard can be completely reconfigured to suit personal tastes. This feature can be a blessing or a curse when keys do not perform the same actions in all applications, but with a little work you can program any key to perform almost any task. Inconsistent keyboard behavior can be eliminated, and applications customized as desired.
In this article, you learn how to achieve consistent behavior for the BACKSPACE, DELETE and ALT keys. The Caps Lock key is switched with the left CTRL key to make the typing of control characters easier. The keys of the editing keypad are configured to perform as labeled. Function keys, and some keys of the numeric keypad, are programmed to perform arbitrary tasks. A shutdown key is also configured.
The keyboard configuration techniques will be demonstrated by a wide range of examples, one program at a time. Where practical, these techniques will be demonstrated for bash, less, Netscape, minicom and Emacs. Furthermore, the keyboard will be made to work as desired, regardless of whether the application is running in an xterm window, in a virtual console, or in an X11 window manager. However, it is assumed that the user has an IBM PC-compatible keyboard.
An IBM PC-compatible keyboard is divided into five blocks of keys. The alphabetic keys and those surrounding them form the main keypad. To the immediate right of the main keypad are two small sets of keys. The upper six keys are the editing keys; the lower four keys are the arrow keys, which are also called cursor control keys. At the far right is the numeric keypad. Finally, the function keys stretch in a single line across the top of the keyboard.
When a function key or an arrow key is pressed, an escape sequence is normally transmitted by the key. An escape sequence is a string of a few characters, the first of which is an ESCAPE control code. The rest of the string is used to distinguish one key from another.
The VT100 family is a set line of text-only display terminals once manufactured by Digital Equipment Corporation. The VT100 has become the de facto standard for ASCII terminals. Its successor, the VT200, is compatible with the VT100 family. However, VT200s also have a row of twenty function keys and six editing keys that the VT100s did not have. The VT200 keyboard is somewhat similar to the IBM PC-style keyboard that is now in general use.
A keypress event occurs when the user presses any key on the keyboard. The event passes through various software programs, eventually resulting in some sort of action (see Figure 1). Ideally, the same keypress will result in a similar action in all programs, thus reducing the user's confusion.
For example, suppose a user is running Emacs inside an xterm under the X Window System and presses the up arrow key. Referring again to Figure 1, the up arrow is pressed, resulting in an event keycode of 98 being generated, which uniquely identifies that key. The X Window System translates this keycode into the “Up” keysym, which is received by the xterm. The xterm then translates the “Up” keysym into the three-character escape sequence “\\eOA” (“\\e” represents the ASCII ESCAPE control code). Emacs receives “\\eOA” as a series of three input events, which are then translated by the function-key-map into the vector [up]. The vector [up] passes unchanged through the key-translation-map. Finally, the global-map maps [up] to the previous-line command, which moves the cursor up one line in the buffer.
One way to approach configuring the BACKSPACE and DELETE keys is to let them act as they do in DOS and MS Windows. That is, BACKSPACE erases the character to the left of the cursor, and DELETE erases the character under the cursor. This is a very convenient arrangement.
It is also a good idea to decide what control codes should be transmitted when these keys are pressed. Based on the key labels, let the BACKSPACE key transmit a BACKSPACE (ASCII code 8, 010 in octal, 0x08 in hexadecimal, CTRL-H), and let the DELETE key transmit a DELETE (ASCII code 127, 177 in octal, 7F in hexadecimal). Simple solutions are usually the best.
The ALT key, which acts somewhat like a shift key, can be configured in one of two ways. Either it can set the eighth bit of the key being pressed with it, or it can cause an ESCAPE to be transmitted just before the key being pressed with it. Both methods will be used at different times. Sometimes it is simpler to configure the ALT key to transmit an ESCAPE. For example, holding down ALT while pressing A would cause the string “\\eA” to be transmitted. However, at other times it will be configured to set the eighth bit of the character being pressed, thus adding 128 to the ASCII code of that character. Meta is a synonym for ALT.
- Readers' Choice Awards 2013
- Linux Kernel News - November 2013
- December 2013 Issue of Linux Journal: Readers' Choice
- Mars Needs Women
- RSS Feeds
- Sublime Text: One Editor to Rule Them All?
- Raspberry Pi: the Perfect Home Server
- Advanced Hard Drive Caching Techniques
- Web Administration Scripts
- IBM Will Minimize Impact of Future Disasters
- thanks for share, great
7 hours 20 min ago
- There are factors which are
12 hours 20 min ago
- Gnome 3 ?
13 hours 5 min ago
- Reply to comment | Linux Journal
17 hours 12 min ago
- "Redis RethinkDB 4.5%" on Best NoSQL Databases
1 day 3 hours ago
- on the ground
1 day 9 hours ago
- I was able to read the whole
1 day 11 hours ago
- since i have read the title i
1 day 14 hours ago
- Belanja Online Cari Voucher Diskon
1 day 14 hours ago
- The kernel doesn't really
2 days 2 hours ago