Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.3: Get xmodmap to remap alt / option in X11 UNIX
I had a tough time getting the alt / option key to work as the Meta (M-x) key in emacs. The escape key does it, but I wanted the key to be where I was most familiar. I'm on a new AlBook with Panther (10.3) and the Apple X11.app installed. Older postings here and elsewhere show how to remap using xmodmap. This works, but I think there are some particulars specific to Panther and Apple's X11.app that aren't reflected in the previous postings. Here are the details. There are just two steps to get this done.

First, put your remapping commands into an .Xmodmap file in your home directory ($HOME/.Xmodmap). With the help of the X11 program xev, I wrote a file that did what I wanted it to.

   clear Mod1
   keycode 66 = Meta_L
   add Mod1 = Meta_L

It tested perfectly in emacs after running

   xmodmap ~/.Xmodmap

You can see what your mod (modifier) keys are mapped to using

   xmodmap -p
Second, open up the X11 preferences from the menu on the top bar. On the "Input" tab, uncheck "Follow system keyboard layout" to allow your keymap changes to overlay on the default X keymap. Then restart X, fire up emacs, and your alt / option key, or others you remapped, should work. Here's a bit more background on what I've discovered:

Reading the man page for Xquartz, I learned that it copies the default aqua keyboard layout into an X11 keymap before startup. Xquartz appears to start up in a non-standard way compared to the standard X, and it won't let you override the keymap unless you allow it as I described above. Other postings elsewhere said you should copy the /etc -> X11 -> xinit -> xinitrc file to ~/.xinitrc and add xmodmap ~/.Xmodmap to the end But this is redundant -- the stock xinitrc script in /etc already checks for an xmodmap file in your home directory. I think those who posted this info were using a pre-Panther version of X11.

Some useful general info on Apple's X11 startup is in the Apple X11 FAQ under "Does X11.app process my ~/.xinitrc?"
    •    
  • Currently 3.00 / 5
  You rated: 3 / 5 (5 votes cast)
 
[20,438 views]  

10.3: Get xmodmap to remap alt / option in X11 | 11 comments | Create New Account
Click here to return to the '10.3: Get xmodmap to remap alt / option in X11' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.3: Get xmodmap to remap alt / option in X11
Authored by: adrianm on Apr 27, '04 02:19:45PM

I tried this but it made no difference.
xev still shows the command key as Meta_L and alt/option as modeswitch.

This is no big deal to me, however, just thought I'd share the experience.

Am on 10.3.3.



[ Reply to This | # ]
10.3: Get xmodmap to remap alt / option in X11
Authored by: MaxMarino on Apr 27, '04 04:07:51PM

tried it, works.



[ Reply to This | # ]
10.3: Get xmodmap to remap alt / option in X11
Authored by: kps on Dec 30, '04 11:41:25AM

Have you remembered to uncheck "Follow system keyboard layout" in X11.app's Preferences? If not, then X11.app may override the keyboard layout set in ~/.xinitrc. Or it may not! It's a race, so the results can be very confusing.



[ Reply to This | # ]
My .Xmodmap file
Authored by: ptwithy on Apr 28, '04 08:20:04AM

!
! On the TiBook, the following keys have caps as listed:
!
! 60 enter (next to right Clover)
! 64 shift (both shifts)
! 67 ctrl
! 68 fn-shift (both shifts)
! 66 option
! 63 "Clover" (both Clovers)
! 59 delete
! 84 "enter" (fn-return)
! 118 (fn-enter)
! 125 "backspace" (fn-delete)
!
! The default Apple mapping is:
! keycode 59 = BackSpace
! keycode 60 = KP_Enter
! keycode 63 = Meta_L
! keycode 64 = Shift_L
! keycode 65 = Caps_Lock
! keycode 66 = Alt_L
! keycode 67 = Control_L
! keycode 68 = Shift_R
! keycode 69 = Alt_R
! keycode 70 = Control_R
! keycode 125 = Delete
!
! I prefer to have meta on option and alt on "Clover"
! I make the enter next to right Clover be Meta_R
! I leave BackSpace and Delete alone, and teach xterm
! to interpret them correctly.
! Cf. http://www.squish.net/docs/delbs.html

! (for powerbooks, where enter is next to right Clover)
keycode 60 = Meta_R
keycode 69 = Meta_R
keycode 63 = Alt_L
keycode 66 = Meta_L

clear Mod1
clear Mod2

add Mod1 = Alt_L Alt_R
add Mod2 = Meta_L Meta_R



[ Reply to This | # ]
My .Xmodmap file
Authored by: vieuxnez on Dec 29, '04 03:39:57AM

I used your .Xmodmap file to get emacs up and running with a meta key, and I was wondering why it worked for the Powerbook, and not any other configuration that I tried to type in? The only difference that I noticed was that you had "add Mod1 = Alt_L Alt_R" what is the reason for the right and left when there is no keycode for the right? Thanks for the .Xmodmap.

---
,Dustin



[ Reply to This | # ]
My .Xmodmap file
Authored by: vieuxnez on May 20, '05 12:47:40AM

Does anyone know where to get the full keycode lists for 15" aluminum, 17" aluminum, and a 15" Tibook? I would greatly appreciate the help.

---
,Dustin



[ Reply to This | # ]
10.3: Get xmodmap to remap alt / option in X11
Authored by: lindalu on Nov 11, '04 02:56:34PM
I have Apple X11 1.0 running and used this command from an xterm to switch the Meta-key from Esc to Alt-Option:
defaults write com.apple.x11 swap_alt_meta -boolean true
I did restart the X11 application. Running XEmacs from a remote Linux server over
ssh -X <user>@<host>
Now the Alt-Option-key is interpreted as Meta in XEmacs.

[ Reply to This | # ]
10.3: Get xmodmap to remap alt / option in X11
Authored by: cgguido on Dec 12, '06 01:52:18PM
I am using X11 1.1.3 - XFree86 4.4.0 on Tiger 10.4.8 on MBP 2.16GHz Core 2 Duo and using: defaults write com.apple.x11 swap_alt_meta -boolean true works great after re-starting X11! Thanks a lot! G

[ Reply to This | # ]
I can't get this to work on a Powerbook, Where can I find a different keycode?
Authored by: vieuxnez on Dec 28, '04 07:22:54PM

I'm trying to figure out how to run dumpkeymap. Am I barking up the right tree, or is there some other way to find out the computer's keycodes?

---
,Dustin



[ Reply to This | # ]
I can't get this to work on a Powerbook, Where can I find a different keycode?
Authored by: vieuxnez on Dec 28, '04 07:31:59PM

Sorry, I just realized that you are working on a Powerbook, too, so I can't figure out why my key remapping won't work. Is there any thing to miss in this? It seems very straightforward to me. Is there maybe a different keycode on a 17" keyboard? (that's what I'm running on, in which case I'd still have to run a keycode search of some sort).

---
,Dustin



[ Reply to This | # ]
I can't get this to work on a Powerbook, Where can I find a different keycode?
Authored by: vieuxnez on Dec 28, '04 07:45:37PM

Sorry, xmodmap -p, as noted above, I just didn't notice it. It's on 63. Thanks.

---
,Dustin



[ Reply to This | # ]