I use English and Persian keyboard layout on my Ubuntu system. I want to change the keyboard layout both with Left Alt+Left Shift and Right Alt + Right Shift. Currently I can not use Right Alt+Right Shift to change the Keyboard layout from Persian to English so that I have to use Left Alt+Left Shift to change it.

Does anybody know how I can set Alt+Shift to change the keyboard layout on both sides? I use ubuntu 12.04.


  • I did the setting to use alt+shift but problem is only Right Alt+ Right shift on changing persian to english language
    – Alireza41
    Mar 10, 2013 at 20:29

6 Answers 6


Ok, yet another try, this one will do the trick I hope... ;)

Credits are due to reverendj1, who described a way of assigning a Custom key to toggle keyboard layout, using setxkbmap, which featured in the workaround alluded to in Edit 2 of my previous answer...

Here is the slightly more involved way, but will give you more flexibility for the key combination. First, copy and paste this script I wrote and name it something like kb_toggle.sh. Make sure to edit LANG1 and LANG2 to be the keyboard layout codes you need.


CURRENT_LANG=$(setxkbmap -query | tail -n 1 | cut -f6 -d ' ')
if [ "$CURRENT_LANG" = $LANG1 ]; then
    setxkbmap $LANG2
    setxkbmap $LANG1

make the file by right-clicking on it -> "Properties" -> "Permissions" tab, then select "Allow executing file as program.

Now, open "System Settings" -> "Keyboard" -> "Shortcuts" tab and select "Custom Shortcuts". Click the + button on the bottom and name the shortcut "Keyboard Toggle" or whatever you want, really. Then give the full path to the script you made earlier in the command box. Hit Apply. Click where it says "Disabled" then you can set the shortcut to whatever you want by clicking your key combination!

I think you'd need to change "de" to "ir".

Again, good luck!


You may even get away with a one-liner, if you prefer:

setxkbmap us,ir -option "grp:alt_shift_toggle"

Now you can switch by pressing alt+shift

See also http://wiki.lxde.org/en/Change_keyboard_layouts and http://www.x.org/releases/X11R7.7/doc/man/man1/setxkbmap.1.xhtml

Edit 2

Depending on how you decide to achieve your goal, you may want to include lv3:ralt_alt in your command, resulting in

setxkbmap us,ir -option "lv3:ralt_alt,grp:alt_shift_toggle"

See man xkeyboard-config | grep lv3 for details:


Right Alt key never chooses 3rd level

   xkeyboard-config  provides  the  description files for the X Keyboard Extension (XKB). The configuration options below are
   usually applied with setxkbmap(1).
  • Thanks. This line works for me: setxkbmap us,ir -option "lv3:ralt_alt,grp:alt_shift_toggle"
    – Farahmand
    Mar 5, 2014 at 17:37
  • What if you want three languages and switch between them circularly but with two directions (right Alt+Shift vs left Alt+Shift Mar 26, 2019 at 7:54
  • @ShacharHar-Shuv You could save the above bash script twice, with the two directions hard-coded. Pretty straight-fwd extension of the above, no? Nov 25, 2019 at 19:15

The "right Alt key" is often (always ?) not the same as the "left Alt key", but corresponds to the AltGr, see for instance

and as such has a different-and-distinct function.

You may want to try to try using xdotool to emulate certain key combination behaviour. Thus, you could set the

  1. Left Alt + Left Shift in the way described by Abdulkader in his answer, and
  2. the second combination as Right AltGr + Right Shift) with xdotool.


For a detailed example of how this can be done in general, with screenshots, plz refer to izx's excellent answer here. Regarding your questions specifically, you could try

xdotool key --clearmodifiers alt+shift

and then assigning this command to the Shift+Level3 Shift (don't type this, just press right_Shift + right_AltGr) shortcut in Custom Shortcuts. Again, plz refer to the relevant part of izx's answer.

Voilá, you're sorted.

Note that if you tried to do it "the other way around" like so

xdotool key --clearmodifiers ISO_Level3_Shift+Shift

(or alternatively, but less likely to work, Alt_R+Shift_R), noting that AltGr is "equivalent to" ISO_Level3_Shift,

you'd probaly get stuck, because "Alt_R+Shift_R" does not seem to be offered in the standard layout switching key dialog.

Further reading: from the xdotool man page:

Generally, any valid X Keysym string will work. Multiple keys are separated by '+'. Aliases exist for "alt", "ctrl", "shift", "super", and "meta" which all map to Foo_L, such as Alt_L and Control_L, etc.

also Remapping the AltGr key to Control with setxkbmap may be of interest to you...

Edit 2

See https://bugs.launchpad.net/ubuntu/+source/xdotool/+bug/696247 and http://code.google.com/p/semicomplete/issues/detail?id=13 ... and the workaround suggested therein (and confirmed to be working as of Nov 2012) of "The workaround, for now, is to use setxkbmap to force your keymap in xmodmap (setxkbmap dvorak, etc)". Thusly, plz refer to my 2nd, separate answer.

  • Thanks. so how can I combine these two keys with xdotool ?
    – Alireza41
    Mar 11, 2013 at 18:30
  • 1
    Updated my answer with a how-to. Mar 11, 2013 at 20:30
  • 2
    right_Shift + right_AltGr does not toggle, and instead only goes one-way English -> Persian
    – Alireza41
    Mar 11, 2013 at 21:00
  • 2
    alt_L + shift_L work correctly and toggle changing
    – Alireza41
    Mar 11, 2013 at 21:06
  • 1
    ok, that's a bit of a bummer; don't know off-hand; will try and find a solution (and/or work-around). Mar 11, 2013 at 21:20

You can use Alt-Shift for both languages

System Settings... → Keyboard Layout → (click on "+" to Add new Language layouts) →

Options... → (click on) "Key(s) to change layout" → (tick) "Left Alt+Left Shift" → Close

enter image description here

enter image description here

  • I did it but its not working when I want to change layout from persian to english with right alt+right shift
    – Alireza41
    Mar 8, 2013 at 17:15

Simply add this command as a startup application:

setxkbmap -option lv3:ralt_alt,grp:alt_shift_toggle us,ir

This should enable both Alt-Shift toggles. However, you will lose the compositing functionality of the right Alt key (e.g.: you won't be able to draw a Euro sign (€) by hitting RightAlt+E).

setxkbmap's options, including language codes, are documented under /usr/share/X11/xkb/rules/base.lst.

You could test the command out in a terminal first before adding it to your autostart applications.

Source: http://crunchbang.org/forums/viewtopic.php?id=11038 (post #7)


go to keyboard layouts from dash, and then click options, there's an option key(s) to change layout check alt+shift. This works for me, both alt and shift works even right alt+ left shift works :)

  • right alt+shift work once. I can't use just right alt+shift to change layout. when layout changed to persian, right alt+shift not working. you can test it.
    – Alireza41
    Mar 8, 2013 at 17:21
  • this looks like a bug.or alternatively right alt seems to have some special role in persian keyboard. I'm using alt+shift to switch between bengali and english and it works fine
    – Anam Ahmed
    Mar 8, 2013 at 17:56
  • 1
    maybe its not working just for switching from persian language
    – Alireza41
    Mar 8, 2013 at 17:58
  • 1
    yes. doesn't work for persian here. maybe right alt has some other role
    – Anam Ahmed
    Mar 8, 2013 at 18:01

Persian and some other layouts are hardcoded to have ISO_Level3_Switch(AltGr or whatever!) instead of Right Alt so when you are in english layout you can use Alt_R + Shift_R/Shift_R + Alt_R to switch to persian but when you are using persian layout the key isn't Alt_R anymore but ISO_Level3_Switch!

Thanks to Sneetsher we know how to change a hardcoded ISO_Level3_Switch back to normal ALT

You must log in to answer this question.

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