Disabling accesskeys (shortcuts) in WordPress

3 June 2008

OS X comes stan­dard with many Emacs key­bind­ings (Ctrl-A to move the cursor to the start of the line, Ctrl-E to go to the end, Ctrl-N and Ctrl-P for next and pre­vi­ous line, etc.), and since I’ve been using these key­bind­ings for about 15 years it’s pretty dif­fi­cult to not hit, say, Ctrl-P when it happens to con­flict with WordPress’s short­cut to publish a post… This is pretty much guar­an­teed to happen at least once whilst writing a post, so this needed to be fixed.

There’s no con­fig­u­ra­tion option to turn this off, and accesskey="p" is buried in the HTML source and I couldn’t figure out a way to filter it out—so the only thing left is JavaScript.

The fix I came up with is below; I’m just dumping this here instead of pack­ag­ing it up because I haven’t tested it on IE and it doesn’t work at all on Firefox (though see below for a so­lu­tion for Firefox). You ba­si­cally need a plugin like this:

func­tion disable_accesskeys() { ?> <script type=“text/javascript”> jQuery(function () { var l = document.getElementsByTagName(“input”); for (var i = 0; i < l.length; i++) { if (l[i].accessKey) l[i].accessKey = ‘’; } }); </script> <?php }

add_filter(‘admin_head’, ‘disable_accesskeys’);

Note: for some reason this doesn’t work with Firefox. (Though neither does Wikipedia’s JavaScript solution, upon which this is based.) However, there’s a better so­lu­tion for Firefox: you can disable access keys/shortcuts com­pletely by setting the ui.key.contentAccess (access via about:config) pref­er­ence to 0 (i.e. zero). (Is there an equiv­a­lent for Safari?)

Access keys are a bit of a failure, I think. They’re not consistent, not trans­par­ent (you don’t know what’s going to happen before hitting a combination), and they can con­flict with what­ever bind­ings your users might be using already.

Turns out that the orig­i­nal Emacs key­bind­ings were fixed the way they are because, when Guy Steele was putting them together, about 20 people at the AI lab at MIT were already using Emacs, and so he couldn’t change the bind­ings without alienating ex­ist­ing users

A few years ago I asked Google answers for a good, authoritative, durable ref­er­ence for Emacs key­bind­ings (I wanted to pass this on to people) and didn’t get any good replies. I wonder if one exists now?

Final Emacs keybinding-related note: on OS X, putting DefaultKeyBinding.dict in ~/Library/KeyBindings makes a whole lot more Emacs key­bind­ings available, as well as making Home and End work the way they do on Windows. (i.e. move cursor to the be­gin­ning and end of the line.)