Friday, 25 December 2009

A Different Kind of Keyboard

The problem

I dislike keyboard layouts (maybe not all of them), but I definitely hate all laptop keyboard layouts and don't get me started on netbooks. Unfortunately, nowadays I am forced to use a laptop most of the time. It is not that I am a dvorak fan. I am fine with the qwerty. What really annoys me is the fact that I am forced to use keys I can only press with my pinkies (alt, super, control, tab, backspace...) while my most skillful fingers the indexes and thumbs just sit there. Or even worse, they force me to move my hands apart from from the home row and back (movement keys, delete, esc...).

Having done my fair deal of LISP coding I know emacs can make your hands hurt.

Technically, there is no need to move our fingers at all. Ten fingers and two possible positions for each of them would provide us with 1024 combinations, far more than keys we use now. That kind of keyboards already exist, they are called chorded keyboards, but require a lot of training and are not exactly what I have in mind.

My method

What I wanted was a method to edit text without having to move my hands or think about where the delete key is in this manufacturer's layout. So why not use letter keys combinations? It would work like pressing ctrl or alt, but instead you would press f (for example) which is much more comfortable.

I also wanted it to run on Linux and for all programs. I couldn't find anything like that, so I had to program it myself.

Good news, it actually works. I use it all the time. You can get the code from the link at the bottom of the post.

F key for movement and selection

When the f key is pressed but not released, the following transformations occur: j turns into left, l into right, k into down... take a look at the picture below:



'But wait a moment' you will say, when I press the key f, I want an "f" to appear on my screen. Well, you can't have it all, from now on you will have to use another letter, "v" sounds quite similar to me... No, really,, using my system you will not get an "f" when you press it, but when you release it, unless you press one of the transformed keys before, in that case the "f" will never appear. That's the only compromise that my system requires. More about how to achieve that later.

D key for deleting

The d key is another of my magic keys. In this case I use it to delete and insert new lines:



  • j -> backspace

  • l -> delete

  • k -> insert new line below (end + enter)

  • i -> insert new line above (home + enter + up)

  • o -> delete from cursor to end of line (shift down + end + shift up + delete)

  • u -> delete line (home + shift down + end + shift up + delete)
So, in a way I am also implementing some little macros.

J for clipboard management

The j key combined with s, d and f is used for cutting, copyingand pasting. Yes, I'm too lazy for Ctrl+x and all that mess.



That covers 90% of my needs when I am programming. I even have a "new line below" key which comes quite handy.

G and H for window management

I use G and H to simulate the meta key (the key between left ctrl and alt). I have setup a lot of hotkeys to manage windows and virtual desktops.

The code

A kernel patch to the input subsystem. I know, I know, that is not the right way to do it. I should have probably used the X event callback functions. However this is a proof of concept, and to be completely honest I tried with the X API and couldn't make it in work 10 minutes, so I went for the fun option: kernel hacking.

Surprise, it actually works! I use it everyday and I love it. There is only a compromise: I have to type properly, that means releasing the keys in the same order I press them, which sounds quite sensible to me anyway.

Here is the link to the github repository (bukbd). It works perfectly with Ubuntu 9.10 kernel for me, but try at your own risk.

TODO:

  1. Get it out of the kernel.

  2. Ability to configure the keys.


X input expert anybody?