Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 16795  / 2 Years ago, thu, december 30, 2021, 10:20:50

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.



Thanks!


More From » keyboard

 Answers
7

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.



#!/bin/bash

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


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!






Edit



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:




lv3:ralt_alt



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).


[#32301] Friday, December 31, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rontablis

Total Points: 293
Total Questions: 123
Total Answers: 104

Location: Austria
Member since Mon, Mar 1, 2021
3 Years ago
;