You don’t know how much you need something until you lose it…

A few weeks ago, I revived my six year old acer aspire, and set it as my default computer at home. But, for a year, my only machine had being a nice thinkpad that my employer, www.uady.mx kindly offered me. One of the most useful features on my thinkpad is that next to the up arrow,  there are two buttons conveniently configured to go back and forward in the browser.

I don’t know why, but the folks in acer thought that it would be most convenient to have an euro and dollar sign next to the up arrow, which I don’t really use.

So, every time I wanted to go back in chrome, I was disapointed for such a bad choice on my laptop. Being a linux guy, instead of been frustrated, I decided to solve this issue. Here is what I did:

As the arch linux wiki explains [*], there are two concepts to learn first:

  1. The scancode is the most basic way of identifying a key in linux. This is an hexadecimal code the kernel assigns to each key it recognizes.
  2. The keycode is analogous to the scancode, but on a higher level. To every scancode there should be a keycode in order for the key to be useful. 

Finally, the X server translates those keycodes into symbols that it understand. Some of those symbols are usual characters to be print as text. But there are a few symbols which are special. In my case, the symbols that make the browser go back and forth are named XF86Back and XF86Forward (no surprises here, uh?)

Therefore to get the thinkpad behavior in my aspire what I needed to do was:
  1. Figure out the scancode of the buttons next to the up arrow.
  2. Find out what is the keycode that should assign to XF86(Back/Forward).

For the first task, I just have to open the file located at /usr/lib/udev/keymaps/acer and it contained the info. (It said that in my laptop those special buttons euro, and dollar where bound to the scancodes 0xB3 and 0xB4). I suppose for other machines there should be a simmilar file if udev is installed.

For the second task, I just googled ;-), somewhere I found that XF86Back should have 166 as keycode, and XF86Forward should be 167. I don’t know if this is a standard, but in my case it worked!
Finally, everything was put together with the next command, executed as root:
#setkeycodes 0xB3 158 0xB4 159

If you are good on math, you should have noticed that 166 = 158 + 8, 167 = 159 + 8. (You certainly did, don’t you? ;-). I learned that the reason for this is historical: What the kernel calls Keycode is not exactly the same the X server uses, but there is an offset of eight units between the kernel’s and the X server’s keycodes.

Voila!. My euro button know makes chrome go back and the dollar button makes it go forward, nothing I had missed more than that =D.
Note that in order to make the changes permanent, if you are on arch, you need to define a systemctl service just as the wiki says.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: