Making OSX Work with a Cheap Mechanical Keyboard

Miroslav Klivansky
4 min readAug 28, 2020

Like many of us, I started working from home full time back in April. At the office I used a standing desk, so I tried to replicate a similar setup at home: two external monitors, plus my MacBook screen. I used a separate keyboard and touchpad to get the height right for my hands when standing. Rather than buying a fancy Mac keyboard, I wanted to repurpose a cheap Monoprice mechanical keyboard that I had around the house. And that’s where the annoyances started…

There were a few issues:

  1. Control key — I use the terminal, tmux, and emacs all the time. The control key is critical, yet they were these little squares in the bottom corners.
  2. Position of Command and Option keys were reversed — The mechanical keyboard used the Alt key for Option, and the Windows key for Command. But their positions on the keyboard were reversed relative to the Mac keyboard. This was messing with my muscle memory and driving me nuts.
  3. Home and End key behavior—There are applications where I’m used to pressing the Home and End keys to go to the beginning or end of the line. On the Mac, these didn’t behave correctly or consistently. This not only bugged me, but cut into my productivity since I often had to undo the results of my typing based on the assumption that they worked right.

Let’s address the fixes for each of these in turn:

Control Key

This one was easy. Since I don’t spend a ton of time shouting on the Internet, I didn’t need my Caps Lock key. I used the native OSX Keyboard utility (in Preferences) to remap the key to be another Control key:

Figure 1: Remapped Modifier Keys

That gave me a big key in the right position (having done the same on my native MacBook keyboard) to use for Control keystrokes.

Reversed Command and Option/Alt Keys

This was a little trickier. It’s easy enough to reverse the operations of the two modifier keys in the applet (see Figure 1). But I look at the keyboard often enough that it creates some cognitive dissonance to not press the “Alt” key when I want Alt. Luckily, it’s easy to remove and replace the key caps on the Monoprice keyboard. All you need is a simple key puller tool:

Figure 2: Key Puller Tool

If you don’t have one of those handy, some people have had luck just using a pair of paperclips like salad tongs. The process was something like what’s in Figure 3 below:

Figure 3: Swapping keys to mimic placement on Mac keyboard

I pulled up the Alt and Windows keys on both sides of the spacebar on the Monoprice keyboard, and swapped them to match the placement on the Mac keyboard. To seat the keys back down, just press down on them once they’re in the right position.

Home and End key behavior

This was the trickiest bit. To get this behavior right, you need to create a new Mac Library file with the correct key bindings. It’s pretty straight-forward if you’re used to editing system files, but may be bit convoluted to those not used to working in the terminal. I followed the contents and comments in Damien Guard’s blog to do this, but only took the part of the key bindings I cared about most:

Figure 4: Key Bindings in ~/Library/KeyBindings/DefaultKeyBinding.dict

But if you just want something quick, you can copy and paste the following code into a terminal:

mkdir -p ~/Library/KeyBindings/
cat <<_EOF_ > ~/Library/KeyBindings/DefaultKeyBinding.dict
{
// home
"\UF729" = moveToBeginningOfLine:;
// end
"\UF72B" = moveToEndOfLine:;
// shift-home
"$\UF729" = moveToBeginningOfLineAndModifySelection:;
// shift-end
"$\UF72B" = moveToEndOfLineAndModifySelection:;
}
_EOF_
chmod 644 ~/Library/KeyBindings/DefaultKeyBinding.dict
killAll Finder

That last line (killAll Finder) restarts the Finder. This is easier than rebooting the Mac like the blog originally suggests.

P.S.

It’s been a long time since I’ve written a blog, and I’ve been wanting to leap back into publishing new content. This was a warm up with something simple and generally useful. Hopefully it helped you.

--

--

Miroslav Klivansky

Extroverted geek with background in enterprise tech. Working with the froods at Pure Storage to dive deeper into analytics and ML. Posts mostly my own opinions.