banner
Previous Page
PCLinuxOS Magazine
PCLinuxOS
Article List
Disclaimer
Next Page

Solving The Case Of The Awful Laptop Keyboard


by Paul Arnote (parnote)

As I've mentioned before in the pages of this magazine, I have a number of computers, all running PCLinuxOS. I also don't keep it a secret that my favorite desktop environment is Xfce. It's not that I particularly dislike KDE, but it's just too resource greedy and too flashy for my needs and tastes. I'd rather use the CPU cycles and memory for useful tasks, instead of flash and glitz. I also don't have the "means" to have the latest, greatest of computing technology available to me, either.

I have a seven or eight year old Lenovo G530 laptop, which I purchased brand new. The only thing that had ever been installed on it had been KDE4 (well, other than Window 7 that came on it ... which was completely wiped from the hard drive shortly after I received the computer). Specifically, I used 32 bit KDE4, even though it has a 64 bit Intel Pentium Dual Core 2.2 GHz processor. When I first installed KDE4 on the computer, there wasn't a 64 bit version of PCLinuxOS available. Since the 32 bit version was running well, I didn't see the urgency of updating to the 64 bit version. It has the same 3 GB RAM installed that came with the computer. The KDE5 release lists 2 GB RAM as the minimum, with 4 GB RAM as the recommended amount of memory.

Over time, the Lenovo laptop went from my "go to" computer to use, to becoming one of the computers that I rarely used, for a number of reasons. First, it needed updating to 64 bit PCLinuxOS, especially since 32 bit version of PCLinuxOS ceased to exist quite some time ago. The 32 bit version of KDE4 was really showing its age and getting a bit long in the tooth from being unable to update it.



But the second reason is a myriad of hardware configuration issues that just never settled well with me. The laptop does not have a SD card reader, which I use quite frequently when downloading images from my digital cameras (and my digital trail cameras during hunting season). It has a paltry two (2) USB ports. Plus, the keyboard isn't laid out exceptionally well, despite having a nice feel when typing. Strike that ... the keyboard layout is awful. Sure, the keyboard layout is "standard" QWERTY keyboard layout. But it's how those "other" keys are laid out that make the keyboard awful. Particularly, the default keyboard layout has the Home and End keys accessible ONLY via a Fn key combination.

These are keys I use all the time! It is so awkward and user "unfriendly" to have to press the Fn + Page Up key for Home, and to press the Fn + Page Down key for End. But, for some odd reason, PrtSc and Pause -- two keys I NEVER use -- got their own keys! I know it seems like a small issue, and it may be -- for some users. But to not have direct access to those two keys that I use all the time made using the keyboard frustrating.



So, very recently (like mid August), I dumped KDE4 and installed the most recent 64 bit version of Xfce from Ika's community remaster. That change came about when my Toshiba laptop (the least capable laptop I regularly use, and the one I use the most) developed problems. So now, I had to use the Lenovo. Which also meant dealing with the annoying and awful keyboard layout.

Something just had to change, and it wasn't going to be me. I run my computer; it doesn't run me.

Certainly, I could just attach a USB keyboard to the laptop. But that would use the only open USB port, since the receiver for my wireless mouse takes up the only other USB port. Not only would that leave me without direct access to any USB ports, but a USB keyboard would take up space I really don't have.



Nope. I had to find a way to remap some keys. In a way, it was a perfect situation. I had two keys on the keyboard that I never used, so they were excellent candidates to be remapped to be my "new" Home and End keys.

I first looked at the X11 utility, xev. I looked around for some online tips on how to use the utility. Let's just say that the documentation I found on how to use xev was like reading a first rough draft (and incomplete rough draft, at that) on brain surgery. There were holes in the documentation that you could have sailed an aircraft carrier through. So, xev quickly got tossed out of consideration. There had to be an easier way.

While looking for documentation on how to use xev, I kept stumbling across instructions on using xmodmap to remap keys on the keyboard. These instructions looked a lot easier and more user friendly than using xev. Lo and behold, it is easier. Plus, xmodmap was already installed on my computer. If you find it missing from your installation, you can easily install it from Synaptic.

The first thing you need to do (from the command line) is run the following command:

xmodmap -pke > keycodes.txt

This saves a copy of the default key code assignments to your current working directory. This way, you have a backup copy, just in case you royally screw things up.

Below is a snippet from the keycodes.txt file:

keycode 77 = Num_Lock NoSymbol Num_Lock
keycode 78 = Scroll_Lock NoSymbol Scroll_Lock
keycode 79 = KP_Home KP_7 KP_Home KP_7
keycode 80 = KP_Up KP_8 KP_Up KP_8
keycode 81 = KP_Prior KP_9 KP_Prior KP_9
keycode 82 = KP_Subtract KP_Subtract KP_Subtract KP_Subtract KP_Subtract KP_Subtract XF86Prev_VMode
keycode 83 = KP_Left KP_4 KP_Left KP_4
keycode 84 = KP_Begin KP_5 KP_Begin KP_5
keycode 85 = KP_Right KP_6 KP_Right KP_6
keycode 86 = KP_Add KP_Add KP_Add KP_Add KP_Add KP_Add XF86Next_VMode
keycode 87 = KP_End KP_1 KP_End KP_1
keycode 88 = KP_Down KP_2 KP_Down KP_2
keycode 89 = KP_Next KP_3 KP_Next KP_3
keycode 90 = KP_Insert KP_0 KP_Insert KP_0
keycode 91 = KP_Delete KP_Decimal KP_Delete KP_Decimal
keycode 92 = ISO_Level3_Shift NoSymbol ISO_Level3_Shift
keycode 93 =
keycode 94 = less greater less greater bar brokenbar bar
keycode 95 = F11 F11 F11 F11 F11 F11 XF86Switch_VT_11
keycode 96 = F12 F12 F12 F12 F12 F12 XF86Switch_VT_12
keycode 97 =
keycode 98 = Katakana NoSymbol Katakana
keycode 99 = Hiragana NoSymbol Hiragana
keycode 100 = Henkan_Mode NoSymbol Henkan_Mode
keycode 101 = Hiragana_Katakana NoSymbol Hiragana_Katakana
keycode 102 = Muhenkan NoSymbol Muhenkan
keycode 103 =
keycode 104 = KP_Enter NoSymbol KP_Enter
keycode 105 = Control_R NoSymbol Control_R
keycode 106 = KP_Divide KP_Divide KP_Divide KP_Divide KP_Divide KP_Divide XF86Ungrab
keycode 107 = Print Sys_Req Print Sys_Req
keycode 108 = Alt_R Meta_R Alt_R Meta_R
keycode 109 = Linefeed NoSymbol Linefeed
keycode 110 = Home NoSymbol Home
keycode 111 = Up NoSymbol Up
keycode 112 = Prior NoSymbol Prior
keycode 113 = Left NoSymbol Left
keycode 114 = Right NoSymbol Right
keycode 115 = End NoSymbol End
keycode 116 = Down NoSymbol Down
keycode 117 = Next NoSymbol Next
keycode 118 = Insert NoSymbol Insert
keycode 119 = Delete NoSymbol Delete
keycode 120 =
keycode 121 = XF86AudioMute NoSymbol XF86AudioMute
keycode 122 = XF86AudioLowerVolume NoSymbol XF86AudioLowerVolume
keycode 123 = XF86AudioRaiseVolume NoSymbol XF86AudioRaiseVolume
keycode 124 = XF86PowerOff NoSymbol XF86PowerOff
keycode 125 = KP_Equal NoSymbol KP_Equal
keycode 126 = plusminus NoSymbol plusminus
keycode 127 = Pause Break Pause Break
keycode 128 = XF86LaunchA NoSymbol XF86LaunchA
keycode 129 = KP_Decimal KP_Decimal KP_Decimal KP_Decimal

I've highlighted the four lines I'm interested in with red text. Make no changes to the keycodes.txt file. Otherwise, it'll be useless to you as a backup file.

Now, run this command:

xmodmap -pke > ~/.Xmodmap

This makes an identical file as keycodes.txt, but this time, the file is placed in your /home directory, and is called .Xmodmap. Remember, the period in front of the filename designates it to be a hidden file. THIS is the file we will be editing.

Now, looking at keycode 79, copy everything to the right of the equal sign. Find keycode 107, and replace everything to the right of the equal sign with the values you copied from keycode 79. Repeat the process for keycode 87, replacing everything to the right of the equal sign of keycode 127. (All of this is for the keyboard on my Lenovo laptop. Chances are high that your laptop keyboard will have a slightly different configuration. The process will be similar, though, for other keyboards.)

So your ~/.Xmodmap file should look like this:

keycode 77 = Num_Lock NoSymbol Num_Lock
keycode 78 = Scroll_Lock NoSymbol Scroll_Lock
keycode 79 = KP_Home KP_7 KP_Home KP_7
keycode 80 = KP_Up KP_8 KP_Up KP_8
keycode 81 = KP_Prior KP_9 KP_Prior KP_9
keycode 82 = KP_Subtract KP_Subtract KP_Subtract KP_Subtract KP_Subtract KP_Subtract XF86Prev_VMode
keycode 83 = KP_Left KP_4 KP_Left KP_4
keycode 84 = KP_Begin KP_5 KP_Begin KP_5
keycode 85 = KP_Right KP_6 KP_Right KP_6
keycode 86 = KP_Add KP_Add KP_Add KP_Add KP_Add KP_Add XF86Next_VMode
keycode 87 = KP_End KP_1 KP_End KP_1
keycode 88 = KP_Down KP_2 KP_Down KP_2
keycode 89 = KP_Next KP_3 KP_Next KP_3
keycode 90 = KP_Insert KP_0 KP_Insert KP_0
keycode 91 = KP_Delete KP_Decimal KP_Delete KP_Decimal
keycode 92 = ISO_Level3_Shift NoSymbol ISO_Level3_Shift
keycode 93 =
keycode 94 = less greater less greater bar brokenbar bar
keycode 95 = F11 F11 F11 F11 F11 F11 XF86Switch_VT_11
keycode 96 = F12 F12 F12 F12 F12 F12 XF86Switch_VT_12
keycode 97 =
keycode 98 = Katakana NoSymbol Katakana
keycode 99 = Hiragana NoSymbol Hiragana
keycode 100 = Henkan_Mode NoSymbol Henkan_Mode
keycode 101 = Hiragana_Katakana NoSymbol Hiragana_Katakana
keycode 102 = Muhenkan NoSymbol Muhenkan
keycode 103 =
keycode 104 = KP_Enter NoSymbol KP_Enter
keycode 105 = Control_R NoSymbol Control_R
keycode 106 = KP_Divide KP_Divide KP_Divide KP_Divide KP_Divide KP_Divide XF86Ungrab
keycode 107 = KP_Home KP_7 KP_Home KP_7
keycode 108 = Alt_R Meta_R Alt_R Meta_R
keycode 109 = Linefeed NoSymbol Linefeed
keycode 110 = Home NoSymbol Home
keycode 111 = Up NoSymbol Up
keycode 112 = Prior NoSymbol Prior
keycode 113 = Left NoSymbol Left
keycode 114 = Right NoSymbol Right
keycode 115 = End NoSymbol End
keycode 116 = Down NoSymbol Down
keycode 117 = Next NoSymbol Next
keycode 118 = Insert NoSymbol Insert
keycode 119 = Delete NoSymbol Delete
keycode 120 =
keycode 121 = XF86AudioMute NoSymbol XF86AudioMute
keycode 122 = XF86AudioLowerVolume NoSymbol XF86AudioLowerVolume
keycode 123 = XF86AudioRaiseVolume NoSymbol XF86AudioRaiseVolume
keycode 124 = XF86PowerOff NoSymbol XF86PowerOff
keycode 125 = KP_Equal NoSymbol KP_Equal
keycode 126 = plusminus NoSymbol plusminus
keycode 127 = KP_End KP_1 KP_End KP_1
keycode 128 = XF86LaunchA NoSymbol XF86LaunchA
keycode 129 = KP_Decimal KP_Decimal KP_Decimal KP_Decimal

I've highlighted the same lines above as I did earlier. But in this version, keycodes 107 and 127 have been reassigned as Home and End keys, replacing the PrtSc and Pause keycodes. Now, my PrtSc key should function as the Home key, while the Pause key should function as the End key.

To test it, run the following command:

xmodmap ~/.Xmodmap

If you did everything correctly, your unused keys should have their new functionality immediately available. So, go ahead and give it your "new" keys a try.

Of course, since this whole key remapping is under the control of xmodmap, the effects are temporary. When you reboot your computer, the same old, poorly thought out, awful keyboard layout will be right back.

Well, that is unless you tell your computer to run the xmodmap ~/.Xmodmap command when your desktop loads. Since I run Xfce, I simply launch the Xfce 4 Settings Manager, go to the Session and Startup utility, then click on the Application Autostart tab. From there, I add the command to run when the desktop is loaded. Most other desktops have similar capabilities.


Taking it further ... if you want

For me, I stopped there. I now had wrestled control of my poorly laid out keyboard from the idiot who decided that PrtSc and Pause deserved their own keys, while Home and End did not. But, could I have gone farther? Yes, I could.

Had I wanted to preserve the functionality of PrtSc and Pause, I could have swapped the keycode definitions around. All I would have had to do is edit the values on the right side of the equal sign for each key. But since I already had absolutely NO use for the PrtSc and Pause keys (I even tried to find a use for those keys, by assigning them to automatically launch a frequently used program ... but at the end of the day, these literally were unused keys), I left the Fn + Page Up key combination for Home intact, kept the Fn + Page Down key combination for End, and simply added two more keys that do the very same thing without having to press the Fn key. Had I wanted to, I could have just as easily converted my Fn + Page Up key to be my new PrtSc key, and converted my Fn + Page Down key to my new Pause key. However, in my mind anyways, that would have been a total waste of time, since I truly never used those keys.

Of course, xmodmap can do more, like even modify the function of the "command and control" keys (Alt, Ctrl, Shift, Super, etc.) of your keyboard. For example, some people think that the CAPS LOCK key has outlived its usefulness, so they remap it to be a Control key. This is completely separate from the fact that some people need to have the CAPS LOCK key disabled by default. The thing is, with xmodmap, you can remap any of the keys on your computer to do whatever you want them to do.

But another great thing about using xmodmap is that the effects on your keyboard are temporary. If you ever want to return your keyboard to its default layout, simply don't run the xmodmap ~/.Xmodmap command (or remove it from the list of applications to autostart in your desktop configuration). Voila! Your keyboard is back to its old, crappy default layout.

Another use for xmodmap might go something like this: one of the keys on your laptop keyboard (well, it could be any keyboard) stops working properly. You can remap one of the keys you rarely use to duplicate the key that stopped working, allowing you to continue along your merry way.

For me, xmodmap allowed me to take a keyboard layout that was frustrating and a hassle to use, and change it to one that worked more like I have become accustomed to working. Now, I don't feel so uncomfortable using the poorly laid out Lenovo keyboard, and my world is "more right."



Previous Page              Top              Next Page