Saturday, January 05, 2008

Using Macintosh keyboard in Ubuntu

I use various computers during a normal working day. I use a Macbook-pro as my laptop, a windows workstation running XP at the client-site where I am currently contracting, and at home I use (probably my favorite computer) an AMD workstation running Ubuntu Gutsy. Since I am primarily a Java developer, I use IntelliJ as my primary workspace, which is of course available on all platforms, the same goes with firefox and quite a few of the other applications I work with as well. One thing that has been annoying me lately, though is that I have not been able to find a really nice keyboard. The key bindings for shortcut keys in some of my favorite applications also varies slightly when using the different platforms. One thing i do know is that it is quite unlikely that I will change the keyboard on my Macbook, which i quite good anyway. I like way the keys both sounds and works.

Some years ago I used to really enjoy typing with those old IBM-style PC-keyboards when using OS/2 workstations at the university. They had really hard keys and made this really load "click" sound. Awfully noisy of course, but I really liked both the way they sounded and behaved. These are anyway not possible to get a hold of anymore.

I really like the looks of the new mac 105-keys keyboards in aluminum, so I got one ow those. The cool ting about this is that it will be much easier for me to switch between the macbook and my buntu workstation. I had a little trouble making the keyboard working as it is supposed to, but after some tweaking, I got it working.

What I had to do

Selecting the correct keyboard layout in Ubuntu is really simple. Just open the "Keyboard" application and you are all set to go. Select the appropriate keyboard layout, which in my case a PC-keyboard with the Norway Macintosh as the variant as shown in the figure.
The next thing you will have to do is enabling the Command-key as a third level chooser (this is usually the windows key on a regular PC-keyboard). Just set it like this:

Now I thought I was almost set to go, having the ()[]{} thing working for me, which is pretty damned important since I am a programmer, and I use these braces all the time. The only thing I discovered was that the keycode=49 was not mapped according to my keyboard. According to my layout it was supposed to be apostrophe bu it was bar. This does not correspond with my current layout, fortunately there are simple ways around this. I didn't know that the keykode was 49 for this key, so then I used "xev" to find it.
After finding the correct keykode, I just launched:

sudo xmodmap -e "keycode 49=apostrophe bar"

to change the mapping to get the apostrophe in the right place. Now I am all set to go. I am probably going to buy myself one of these keyboards for the windows-workstation I am using at the client-site as well.