Archive

Posts Tagged ‘firefox’

Quick Guide to Customizing Keyboard Bindings in OS X

October 21st, 2009 Dallas No comments

I love my Mac. In fact, I love just about everything about it. The places where it fails to please tend to be when handling input devices – specifically keyboard and mouse input.

The default acceleration curve for mouse motion is bizarre. There are two speeds – slow and relativistic. That was fixed on day one thanks to USB Overdrive. While it does cost $20, it is well worth it for the ability to use an external mouse.

The keyboard bindings took a while to become irritating, probably because as a laptop user some degree of keyboard discomfort is to be expected. The confined space means that come concessions must be made; keys are squished or missing, some are given dual roles, and some are out of place. As a programmer, I do a lot of navigation on the keyboard. Unless I’m moving between large chunks of code, I don’t touch the mouse at all. Because of this, I use a full size USB keyboard to give me access to all of those nifty keys that are missing on the laptop (Home/End/Page Up/Page Down). Unfortunately OS X maps different functions to some of those keys than I’m used to. For instance, “Home” and “End” scroll to the top and bottom of the document instead of the beginning and end of the current line of text. Fortunately I’ve found a resolution.

User specific keyboard bindings are stored in /Users/{User Name}/Library/KeyBindings/DefaultKeyBinding.dict. Note that this directory and file may not exist at first, so you may need to create it. If this is the case, you’ll also need to create the DefaultKeyBinding.dict file. I recommend copying the system wide keyboard bindings file from /System/Library/Frameworks/AppKit.framework/Resources/StandardKeyBinding.dict. This will give you a good base to work from. I don’t recommend modifying this file directly, as if you mess something up you’re really screwed.

Now that you’ve copied the file, all you have to do is modify it to suite your fancy. It’s possible to do this by hand, but it’s easier to use a specialized editor. I recommend the KeyBindingsEditor (free download). Fire up KBE and look for the “Home” key (make sure the “Modifiers” field is clear), then change the action to moveToBeginningOfLine. Do the same for the “End” key, except the action will be moveToEndOfLine. Make any other modifications you want, save the file, and restart any running applications to obtain the new bindings.

Easy right? There are a few exceptions (imagine that). Some applications, such as Firefox and Eclipse, ignore these key bindings altogether. I’ve figured out how to fix Firefox, but I’m not an Eclipse user (give Netbeans another try, the new version is really nice). Fixing Firefox isn’t nearly as straightforward and can’t be done on a per user basis (all changes are global). In fact, this was reported as a bug back in 2003 and is still an open item.

First you need to obtain the platformHTMLBindings.xml file. This contains all of the keyboard bindings used by Firefox and its location depends on what version you’re running. For pre-1.05 users (are there any?), the file is in /Applications/Firefox.app/contents/MacOS/res/builtin/. For the rest of us it’s inside the /Applications/Firefox.app/contents/MacOS/chrome/toolkit.jar archive. A .jar archive is nothing more than a renamed .zip file, so you can extract its contents as you would any other .zip. Once you extract the contents, you’ll find the file in the content/global/ directory. After you modify it you will need to update toolkit.jar with the new version so don’t delete anything and be sure to back up the original.

Inside platformHTMLBindings.xml, you’ll need to find and modify the following nodes in the <handlers> section of <binding id="inputFields">, <binding id="textArea">, and <binding id="editor">:

<!-- Change cmd_scrollTop to cmd_beginLine -->
<handler event="keypress" keycode="VK_HOME" command="cmd_scrollTop"/>
 
<!-- Change cmd_scrollBottom to cmd_endLine -->
<handler event="keypress" keycode="VK_END"  command="cmd_scrollBottom"/>

You can find other commands at Customizing Mozilla.

After you’ve made your modifications zip the folder back up, change the extension to .jar,  and copy it over the toolkit.jar archive.

Whew, OK that’s it. If you have any questions shoot me an e-mail at edwardsdl@gmail.com.

Categories: General Tags: , , , ,