Why won't my xmodmap command run on startup/login?

9,763

Solution 1

~/.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.

Solution 2

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.

Solution 3

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:
9,763
cukabeka
Author by

cukabeka

Updated on September 17, 2022

Comments

  • cukabeka
    cukabeka over 1 year

    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?

  • cukabeka
    cukabeka over 13 years
    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?
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 13 years
    @Matthew: Untested: launch gconf-editor, browse to /desktop/gnome/peripherals/keyboard/general, and edit the known_file_list entry to remove .Xmodmap.
  • cukabeka
    cukabeka over 13 years
    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?
  • Admin
    Admin about 13 years
    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.
  • user3376703
    user3376703 over 10 years
    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.
  • plnx
    plnx over 9 years
    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