Designing a keyboard layout
My current obsession with alternative keyboard layouts started, strangely enough, by reading an article about optimising the symbol layer of a keyboard running qmk.
For those who don't know, there is a whole world of custom-built mechanical keyboards running open source firmware (usually qmk or zmk, and a common feature of these keyboards is additional layers, enabled by holding down a key just like shift on a regular keyboard switches the keys from lowercase to uppercase letters.
Just like lowercase and uppercase, the number row on a regular keyboard turns into a row of symbols when the shift key is held.
Being able to configure new and customized “shift keys” is really useful if your keyboard has fewer keys than a standard keyboard. For example, on a keyboard without the number row, a “number” shift key could turn the top row of letters into numbers.
Why would you want fewer keys on a keyboard? More is more, right? Well, the answer generally is ergonomics (perhaps also, to some degree, aesthetics). The theory is that by not having to move the hands to reach distant keys, strain on the wrists and fingers is reduced.
It turns out, once you have the source code for your keyboard available, there really is no limit to what you can do. Why stop at adding new layers, when you can rethink the design of the keyboard from scratch?
(I have a ton of other custom keyboard modifications in my qmk fork).
This is not a new idea. In fact, redesigning the keyboard to reduce finger motion is the exact idea behind the Dvorak keyboard layout, designed in 1936.
The Dvorak layout does a number of things in order to improve the keyboard usage experience: First, it tries to move the most commonly used letters closer to the home row. The idea here is that since the fingers should rest on top of the middle row (asdf
and jkl;
on a standard QWERTY layout) in order to minimize the movement required to reach any key, a way to further reduce movement is to place the most commonly used letters right there.
The second thing that Dvorak does is move the vowels to one hand and most of the consonants to the other. This increases alternation between the hands, giving each hand more time to get into position before having to hit a key.
However, there are a couple of problems with the Dvorak layout which has led people to try to come up with better alternatives. Most notably, Dvorak places L in a position which is awkward to reach for most people, despite L being one of the most common letters in english.
Most famous of these is the Colemak layout, which manages both to be a well optimized layout while retaining a lot of similarities with QWERTY in order to keep commonly used shortcut keys like copy and paste in their original positions.
A common modification of Colemak is the Colemak-DH layout, which notes that it's generally more comfortable for the index finger to reach down to the bottom row than to stretch inwards to hit the QWERTY G or H positions. Therefore, it moves D and H to the index finger bottom row positions. This is generally considered a very good layout and the first layout to recommend to someone looking to get into alternative keyboard layouts.
In fact, there are a lot of variables that a keyboard layout can be optimized for, and some of them are contradictory to each other, making keyboard layout optimization a really fascinating problem. One observation is that by optimizing a layout for english, we may accidentally make it less optimal for a different language. For example, I type a lot in either english or swedish. Since these are related languages, the letter frequency is generally similar between the languages. However, some of the least common letters in english are some of the most common in swedish (notably K and J). I will get back to this issue later in this essay.
When looking at bigrams and trigrams – common sequences of two or three letters like HE or YOU – it gets even more complex. In fact, bigrams introduces some of the variables that a modern layout generally tries to optimize for beyond finger distance travelled:
- SFB, or Same Finger Bigram: Having to use the same finger twice in a row, for example when typing DE or CE on a qwerty keyboard.
- Having to stretch across all three rows as when typing CE can be considered a separate stat, commonly called Same Finger Skipgram or SFS.
- LSB / LSS: Lateral Stretch Bigram / Skipgram. This refers to having to stretch adjacent fingers across rows, like typing BE on a QWERTY layout.
Another set of variables to optimize for relates to rolls and redirections. A roll is when a sequence of letters can be typed by “rolling” the fingers across the keyboard, as when typing WER on a QWERTY keyboard. Generally, inward rolls (from left to right on the left hand, or from right to left on the right hand) are considered more comfortable. Redirection happens when having to switch directions for a roll, for example when typing RET on a QWERTY keyboard.
All this is the background against which I decided to design my own keyboard layout.
I have based my design on some of the most modern and efficient designs out there, like Hands Down Neu, APTv3, Nerps and Semimak. My goal was to create a layout which works well not only for english, but for swedish, vim and programming in general as well.
Mainly, my problem with layouts purely optimized for english is the positions of J and K. As mentioned earlier, these letters are more common in Swedish. Another letter like this is V. (I am not going to mention the letters ÅÄÖ in this essay; for the purposes of this essay it can be assumed that these letters take the places of the ,./ keys on a QWERTY keyboard).
I am also an avid vim user and in vim, the J and K keys are used to move the cursor between rows. This means that a layout which optimizes for english text tends to make those motions less comfortable in vim.
After some iterations and a lot of trial and error, this is my current version of this layout:
w c m g p q y o u '
r s n t v k h e i a
z x l d b j f / . ,
I have been calling it cmpneu
or wmpneu
, although that name fits less well now that I've rearranged the top row... so I'll try to come up with a better name at some point.
Here are some statistics for this layout generated by the a200 analysis software. It compares very well to other layouts optimized for english alone while still making K, J and V more comfortable for swedish and vim usage.
Trigrams
========
Alternates - Total: 25.64%
Rolls - Total: 52.39% In: 19.52% Out: 32.87% Ratio: 0.59
Onehands - Total: 3.89% In: 2.20% Out: 1.69% Ratio: 1.30
Redirects - Total: 4.93%
Unknown - Total: 0.00%
Same Finger
===========
SFB - 1.09% DSFB - 5.67%
SFT - 0.00% SFR - 6.37%
Finger Use
==========
Left - Total: 38.92% LP: 6.28% LR: 6.48% LM: 10.85% LI: 15.30%
Right - Total: 42.57% RP: 7.87% RR: 9.36% RM: 16.30% RI: 9.04%
Thumb - Total: 18.50%
Row Use
=======
Top - 25.17% Home - 60.31% Bottom - 14.52%