Home | Developer Blog

Strange Leopard key binding bug

Muscle memory is a powerful thing. I’ve been using Mac OS X for over six years, but my history with Windows, and DOS before it, have defined how my brain expects certain tasks to map to keys on the keyboard. I’ve never gotten used to the text editing key bindings on Mac OS X. I grew up with things like CONTROL-LEFT and CONTROL-RIGHT moving the cursor by a word, and SHIFT-DELETE, CONTROL-INSERT, and SHIFT-INSERT being cut, copy and paste respectively. Luckily, Mac OS X provides for customization of key bindings, and I managed to create a set of key bindings that met most of my needs… Until Leopard arrived.

My key bindings file includes the following two bindings:

"$^\UF702" = "moveWordLeftAndModifySelection:";
"$^\UF703" = "moveWordRightAndModifySelection:";

These map CONTROL-SHIFT-LEFT and CONTROL-SHIFT-RIGHT to moving one word to the left or right while modifying the selection. In this syntax “$” represents SHIFT and “^” represents CONTROL, and \UF702 and \UF703 are the left and right arrow keys. These two bindings are really ingrained in my muscle memory.

These key bindings worked fine in previous versions of Mac OS X, but in OS X 10.5 Leopard, the “right” version stopped working. The “left” version continued to work fine. After living with this for months, and getting ever more frustrated, I finally figured out how to fix the problem. Apparently, in 10.5, the ordering of the modifiers ($ and ^) make a difference… sometimes. The following key binding entries work fine in Leopard:

"^$\UF702" = "moveWordLeftAndModifySelection:";
"^$\UF703" = "moveWordRightAndModifySelection:";

As crazy as it seems, the ordering of the modifiers doesn’t make any difference if the key is LEFT, but does if the key is RIGHT. Go figure.

By the way, a great guide to customizing Mac OS X key bindings can be found here.

Post a Comment