Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to run this command every time I log in (or every time I start up, if that doesn't work): xmodmap -e 'keysym Delete = Menu' -e 'keysym Menu = Delete'

I've tried many things. I put the command in System > Preferences > Startup Applications. I put it in a .sh file, marked it chmod +x and put that file in System > Preferences > Startup Applications. I put the script in /etc/init.d. I put the commands in ~/.profile. Nothing seems to work.

Finally, I put this in my ~/.profile:

touch test1
xmodmap -e 'keysym Delete = Menu' -e 'keysym Menu = Delete'
touch test2

Both test1 and test2 get created, but the keys are still not remapped. If I just copy/paste the command and run it manually, it works fine. But it won't run on login. Any ideas?

share|improve this question
up vote 11 down vote accepted

~/.profile runs early in the login sequence. If your desktop environment configures a keyboard layout, it can overwrite the settings you've just loaded.

Put your settings in a file called ~/.Xmodmap:

keysym Delete = Menu
keysym Menu = Delete

Under the default Gnome environment in Ubuntu 10.04, the next time you log in, you will be prompted as to whether to load ~/.Xmodmap. Load it, and tick “don't ask me again”. Then your .Xmodmap will be applied after the default settings.

share|improve this answer
    
Thanks, this worked perfectly. Out of curiosity, how would I get back to the dialog that I checked "don't ask me again" for if I wanted to some time in the future? – Matthew Pirocchi Sep 6 '10 at 20:33
1  
@Matthew: Untested: launch gconf-editor, browse to /desktop/gnome/peripherals/keyboard/general, and edit the known_file_list entry to remove .Xmodmap. – Gilles Sep 6 '10 at 21:25
    
This worked for me on the Ubuntu 10.10 beta back when you first answered this question. I did a fresh install of Ubuntu 10.10 yesterday, and put an identical .Xmodmap file in my home folder. When I logged back in, I got the dialog, loaded .Xmodmap, and ticked the box just like before. But it doesn't seem to be remapping the keys. I checked in gconf, and .Xmodmap is definitely in the known_file_list. Any ideas? – Matthew Pirocchi Sep 18 '10 at 16:47
    
This is also not working for me on Gnome 3.10.1/Archlinux. I wonder if something hasn't been adjusted in the order Gnome loads keyboard layouts. – Caleb Dec 28 '13 at 10:38
    
For Gnome 3.10 no longer loading ~/.xmodmap, I found a solution that worked at the bbs.archlinux.org/viewtopic.php?pid=1194968#p1194968 : disable Gnome's keyboard plugin. $ gsettings set org.gnome.settings-daemon.plugins.keyboard active false – plnx Feb 3 '15 at 21:59

I found that in the place in Gconf-Editor mentioned above the name of your revised keyboard layout should appear twice, once under "known_file_list" and once under "update_handlers". As to why Ubuntu sometimes puts in the latter entry, and sometimes doesn't... well, it keeps you on your toes, doesn't it?

Incidentally, after a lot of research I used the above tweak to re-assign the Left Windows key. I put the following statement in my own keyboard layout to make it duplicate the Left Arrow key:-

keycode 133 = 0xFF51

(Check that those are the right codes for you by going into xev and pressing first one key then the other.)

It's only a little point, but while I'm on the Internet it gives me a convenient "Back" key - Alt+Win with the left hand. I can do it without looking.

share|improve this answer
1  
Alan wrote: "I found that in the place in Gconf-Editor mentioned above the name of your revised keyboard layout should appear twice, once under "known_file_list" and once under "update_handlers"." I can confirm that Alan is correct. In Ubuntu 10.10, in order for your ~/.Xmodmap file to have an effect, ".Xmodmap" has to appear in both the "known_file_list" and the "update_handlers" list under /desktop/gnome/peripherals/keyboard/general in gconf-editor. Thanks, Alan. – user74689 Apr 3 '11 at 4:49

Some systems look for a file named ~/.Xmodmap and execute the commands found there. Try putting these lines in that file:

keysym Delete = Menu
keysym Menu = Delete
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .