One of the things I do from my Macbook (running OS X 10.6) is to use X11.app to connect to other machines and display X applications back to my desktop. A number of those applications, particularly Firefox, want to use key combinations involving Alt to do various things (eg, Alt-left arrow and Alt right-arrow). Unfortunately by default the OS X X11 keybindings use the Alt key as a Mode Switch key (for entering extended characters), and have no key that sends the Alt modifier.

As described in this Mac OS X Hint from 2003 and this Inkscape forum posting the solution to this problem is to use xmodmap to remap what happens when the Alt keys are pressed.

To do this:

  • run xev to determine what keycodes are sent when the relevant Alt keys are pressed (Left Alt = 66; Right Alt = 69 on my keyboard)

  • create ~/.Xmodmap or add to it, to include the text below

  • run xmodmap ~/.Xmodmap, or stop all X11 applications and exit X11.app.

clear Mod1
keycode 66 = Alt_L
keycode 69 = Alt_R
add Mod1 = Alt_L
add Mod1 = Alt_R

This is likely to make it difficult to enter foreign characters through X11, but it's not a major concern for me. If it did become a problem I'd be inclined to leave the right Alt key as the mode_switch, and the left Alt key as Alt (consistent with Alt/AltGr on many European PC keyboards).

(This blog post from 2006 also contains some useful discussion in the comments, but the actual tip seems confused as it doesn't seem to do what it says it does, and there doesn't seem to be a need for what it does do.)

I also enabled the "Emulate three button mouse" option (X11 -> Preferences -> Input), which makes the Alt/Option key the modifier to get Button 3, which amongst other things is "Open in New Tab" in Firefox. Combined with the above this makes the Alt/Option key the useful key for opening new windows and moving back/forwards in history.

Firefox on Linux keybindings

While doing this I also changed the Firefox accelerator key on one of my Linux systems back to the default (Control) since until I discovered the above my custom setting (Alt) wasn't doing anything when displayed against the OS X X11.app. As described on the Firefox Unix Customisation page this is done with the preference:

prefs.js:user_pref("ui.key.accelKey", 17);

(where 17 is Control, 18 is Alt, and 224 is Meta.) (I chose not to set it to Meta because that would then interfere with local key sequences, and not to put it back to Alt after finding the above fix because if it's going to be different from the Apple browser, it might as well be consistent with the Linux defaults.)