3

I'm trying to re-map my left Alt key to the Alt Gr and Alt Gr to left Alt. So far I've been able to do it in terminal, but it never runs it on start up. I've read multiple Ask Ubuntu questions, but none of them have worked so far.

I have tried multiple commands and methods, but none of them worked

Putting the script in /etc/rc.local like this:

sh /home/dani/Scripts/altgr_to_alt.sh

Adding it in cron

@reboot sh /home/dani/Scripts/altgr_to_alt.sh
@reboot bash /home/dani/Scripts/altgr_to_alt.sh
/home/dani/Scripts/altgr_to_alt.sh

Putting it in /etc/init.d/

/etc/init.d/alt_to_gr.sh

Adding it as a startup program, the command being

/home/dani/Scripts/altgr_to_alt.sh
sh /home/dani/Scripts/altgr_to_alt.sh
4

Solved it myself

The second post here solved it Add the following line to the command field in Startup Applications

/home/dani/Scripts/altgr_to_alt.sh

And here is what the script looks like if someone is wondering

#!/bin/bash
echo "Changing keys..."
xmodmap -e "clear mod1"

xmodmap -e "keycode 108 = Alt_L Meta_L"
xmodmap -e "keycode 64 = ISO_Level3_Shift"
xmodmap -e "add mod1 = Alt_L Meta_L"

echo "Changed keys!"
echo

You have to make it executable if you want to run it at startup. I did this with chmod 755 altgr_to_alt.sh

  • for some random reason I can't explain myself, this works (on ubuntu 18.10) whereas @mateusz-piotrowski's answer doesn't. (it seemed too me they would have been equivalent). Thanks to both of you ! I needed that for a long time ! – Nicolas Marshall Nov 6 '18 at 16:19
  • I can confirm this worked for me as well on Ubuntu 18. – James Heston Nov 22 '18 at 20:52
0

A slightly different approach:

  1. Add the following lines to ~/.Xmodmap:

    clear mod1
    
    keycode 108 = Alt_L Meta_L
    keycode 64 = ISO_Level3_Shift"
    add mod1 = Alt_L Meta_L
    
  2. Open Startup Applications and add a new rule with the following command:

    /bin/bash -c "sleep 10 && /usr/bin/xmodmap ~/.Xmodmap"
    

    This will wait 10 seconds so that it doesn't run too early and then modifies the keyboard mapping based on the content of ~/.Xmodmap which is a pretty standard file for keeping a remapping configuration.

  • doesn't seem to work for me on ubuntu 18.10 – Nicolas Marshall Nov 6 '18 at 11:46
  • @NicolasMarshall I'm not using Ubuntu anymore. I switched to FreeBSD and never looked back. – Mateusz Piotrowski Nov 6 '18 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.