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.
|Designing Electronics with Linux||May 22, 2013|
|Dynamic DNS—an Object Lesson in Problem Solving||May 21, 2013|
|Using Salt Stack and Vagrant for Drupal Development||May 20, 2013|
|Making Linux and Android Get Along (It's Not as Hard as It Sounds)||May 16, 2013|
|Drupal Is a Framework: Why Everyone Needs to Understand This||May 15, 2013|
|Home, My Backup Data Center||May 13, 2013|
- RSS Feeds
- Dynamic DNS—an Object Lesson in Problem Solving
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- A Topic for Discussion - Open Source Feature-Richness?
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Validate an E-Mail Address with PHP, the Right Way
- What's the tweeting protocol?
- Tech Tip: Really Simple HTTP Server with Python
- Kernel Problem
2 hours 1 min ago
- BASH script to log IPs on public web server
6 hours 28 min ago
10 hours 4 min ago
- Reply to comment | Linux Journal
10 hours 36 min ago
- All the articles you talked
13 hours 29 sec ago
- All the articles you talked
13 hours 3 min ago
- All the articles you talked
13 hours 4 min ago
17 hours 29 min ago
- Keeping track of IP address
19 hours 20 min ago
- Roll your own dynamic dns
1 day 34 min ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi
It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?