This weird keyboard technique has improved the way I type.

by Dreams of Code
Share:
This weird keyboard technique has improved the way I type.

This Weird Keyboard Technique Has Improved the Way I Type

For the longest time, I chose not to use a tiling window manager. Not because I didn't like the idea of one—I actually rather did. Instead, it was due to the fact that using one often makes use of a certain keyboard key: the Super key, which is better known as the Windows key on Windows or the Command key on macOS.

This key is often located one or two keys away from the space bar on a traditional keyboard, which can make it a bit of a pain to reach. I don't mean that figuratively either—I mean it can actually cause physical pain. At least it did in my case, as I have a pretty bad habit where I will unnaturally bend my thumb in order to reach this key. After doing it for a couple of years, it had started to take its toll.

So when it came to tiling window managers, which often make heavy use of either the Super or even worse the Alt key, I ended up just avoiding them in an attempt to prevent my thumbs from suffering long-term health effects.

However, about 6 months ago, I discovered a new keyboard technique—one that not only enabled me to use a tiling window manager but also improved my entire developer experience. That technique is called Home Row Mods, which allows me to easily use the modifiers of Super, Alt, Shift, and Control without ever leaving the home row.

This not only makes it possible for me to use a tiling window manager comfortably but also makes me much more effective when working in the terminal, making it much easier to navigate tmux, Neovim, and even just the CLI.

How Home Row Mods Work

The way that Home Row Mods work is, well, kind of described in the name. The basic idea is that you overload eight of the keys found on your keyboard's home row with additional behavior whenever those keys are held rather than when tapped.

To show what I mean, let's quickly take a look at the behavior of my D key:

  • If I tap this key, it acts as it normally would, causing the letter D to be typed out
  • However, when I hold this key, it has a different behavior, sending the key code of Left Shift

This means that I'm able to hold this key down with my left hand and type out other keys using my right, causing them to send their shifted codes.

But what about if I want to type an uppercase D? How can I do this when I also need to hold down the D key in order to activate Left Shift? Well, that's where the right-hand side of the Home Row Mods comes in. I've configured a key on the right-hand side of the keyboard that when held will act as the Right Shift modifier—the K key.

Therefore, by holding this key down with my right hand, I'm able to type uppercase letters using my left, including the aforementioned D key. By having both of these keys act as Shift, I'm able to easily use the Shift modifier with any other key without ever leaving the home row or stretching to reach where the Shift keys are typically located.

The Complete Layout

In addition to Shift, there are three other modifiers that are also used, which ends up as eight total keys that make up the Home Row Mods. These are the A, S, D, F keys on the left-hand side and the J, K, L, ; keys on the right.

The benefit of using these keys is that because of their location, it makes it much easier to activate these modifiers compared to their original positions, causing your hands to hardly ever leave the home row, making it extremely efficient when it comes to touch typing.

As for what the modifier keys actually are, in my configuration I have it as follows:

Left-hand side:

  • A key when held acts as Left Super
  • S key when held acts as Left Alt
  • D key when held acts as Left Shift
  • F key when held acts as Left Control

Right-hand side:

  • J key when held acts as Right Control
  • K key when held acts as Right Shift
  • L key when held acts as Right Alt
  • ; key when held acts as Right Super

I actually chose this layout for a good reason—to correlate each modifier and finger based on how often I use that modifier with the finger strength. For example:

  • The Control key is one of my most used modifiers, therefore I assigned it to the finger that has the highest strength (my index finger)
  • The Super key is my least used modifier, so I assigned it to my weakest finger (my pinky)

By assigning the modifiers this way, it helps to reduce any finger fatigue when it comes to coding, which can be a pretty common occurrence when you make use of modifiers heavily. Just ask anyone who's ever suffered from Emacs pinky!

Real-World Benefits

This layout works really well for my own terminal configuration. Take for example tmux, which is pretty much the application I live in when it comes to writing code. In my case, I have it configured so that I'm able to cycle through windows by holding Alt and Shift and using either the H or L keys to go left or right respectively.

This means that by using Home Row Mods, all I need to do is hold S and D with my left hand, and I'm free to cycle through the windows using my right hand, tapping the relevant key.

Not only this, but because I have the Control key assigned to my index finger, it also makes it incredibly easy for me to jump around my tmux splits—holding the F key down with my left hand and using the H, J, K, and L keys in order to navigate.

Additionally, I also make heavy use of the Control key when navigating Neovim, as well as using the Control and Alt keys for navigating CLI commands. And of course, using Home Row Mods has not only made it possible for me to use a tiling window manager but has also made me much more efficient when doing so, as the Super key is now much easier for me to reach.

Therefore, by setting up Home Row Mods on my keyboard, it means I'm able to navigate my development environment with much greater ease and speed whilst also causing me to make fewer mistakes when typing due to keeping my hands on the home row.

More importantly than speed and accuracy, however, is the fact that it's just better for my hand health. Considering that I plan on writing code until I physically can't anymore, keeping my hands in good health is something that I take seriously.

So yeah, whilst Home Row Mods aren't for everyone, for me they're here to stay, and I've had them set up on every keyboard that I've used since discovering them, including the built-in ones on my laptops.

How to Set Up Home Row Mods

If you're using a keyboard that runs customizable firmware such as QMK or ZMK, then you can set up Home Row Mods using the mod-tap behavior. I actually have a couple of examples for both firmware in a GitHub repo for this article.

If you don't happen to have a keyboard with firmware that you can configure (such as if you're using a laptop), then instead you can use a tool such as Kanata, which is actually what I used for my article on modifying the Caps Lock key.

Setting Up Kanata

Kanata is an open-source software keyboard remapper for Linux, macOS, and Windows, and is what I use to remap keys on my Linux laptops and on macOS.

To install Kanata is actually pretty simple. You can either install it via Cargo or through your operating system's package manager if it's available. If you're using macOS, then you'll also need to install the Karabiner Virtual HID package as well.

Once you have Kanata installed, you then need to define a Kanata configuration in order to add Home Row Mods. To do this, you'll first want to create a new configuration file. In my case, I'm creating one called kanata.kbd.

Basic Configuration

Let's begin by setting up just a single key to make it easier to explain the process. The key I'm going to start with is the A key, which we want to assign the modifier of Left Super.

First, we need to define the keys that we want Kanata to process using the defsrc function:

lisp
(defsrc
  a
)

Next, we want to define the overridden behavior that we want our A key to be mapped to. I like to define aliases to do this:

lisp
(defalias
  a-mod (tap-hold 200 200 a lmet)
)

The tap-hold function accepts four parameters:

  1. Tap timeout (200ms): The amount of time in milliseconds you have to trigger a key repeat behavior by tapping and holding
  2. Hold timeout (200ms): The number of milliseconds to hold a key for the hold behavior to occur
  3. Tap action: The a key code
  4. Hold action: The Left Meta (Super) key

Next, we need to overwrite our existing A key using the deflayer function:

lisp
(deflayer base
  @a-mod
)

Finally, we need to tell Kanata to process all keys:

lisp
(defcfg
  process-unmapped-keys yes
)

Complete Configuration

Here's a complete configuration with all Home Row Mods set up:

lisp
(defcfg
  process-unmapped-keys yes
)

(defvar
  tap-time 200
  hold-time 200
)

(defsrc
  a s d f   j k l ;
)

(defalias
  a-mod (tap-hold $tap-time $hold-time a lmet)
  s-mod (tap-hold $tap-time $hold-time s lalt)
  d-mod (tap-hold $tap-time $hold-time d lsft)
  f-mod (tap-hold $tap-time $hold-time f lctl)
  j-mod (tap-hold $tap-time $hold-time j rctl)
  k-mod (tap-hold $tap-time $hold-time k rsft)
  l-mod (tap-hold $tap-time $hold-time l ralt)
  ;-mod (tap-hold $tap-time $hold-time ; rmet)
)

(deflayer base
  @a-mod @s-mod @d-mod @f-mod   @j-mod @k-mod @l-mod @;-mod
)

To run this configuration, open a terminal and run:

bash
sudo kanata -c kanata.kbd

Making It Permanent

One additional thing you may want to do when using Kanata is to make sure that it launches whenever you start up your computer. If you're using NixOS, this is pretty easy to do using the Kanata service in your configuration. However, if you're using a different Linux distro or macOS, you'll need to configure this for whichever launch service that you're using. In the repo, I've created examples for both systemd on Linux and for Launch Control on macOS.

Conclusion

Home Row Mods have really improved the way that I type when it comes to working on a keyboard, and as is often the case with information that I share, I don't think I'll go back to a time where I didn't use them.

Whether you're dealing with thumb pain, looking to improve your typing efficiency, or just want to make better use of your keyboard, Home Row Mods might be worth trying out. The initial learning curve can be a bit steep, but the long-term benefits for both productivity and hand health make it worthwhile.

Resources

This article was sponsored by Brilliant.org - where you learn by doing with thousands of interactive lessons in math, data analysis, programming, and AI.

Share:
This weird keyboard technique has improved the way I type. | Dreams of Code