I was frustrated at how I had to bind a different keybinding to each layout I wanted to switch to. So I came up with a simple script which simply checks a file and changes the keyboard layout accordingly. I needed to switch between US and US International, so those are the two layouts my script checks for. However, this can easily be adapted for more than two layouts.
Here's the script:
#!/bin/bash KEYBOARD=`cat ~/.keyboard` test "$KEYBOARD" = "us" RETURN=$? if [[ $RETURN -eq 0 ]] then setxkbmap us intl echo "us intl" > ~/.keyboard exit fi if [[ $RETURN -eq 1 ]] then setxkbmap us echo "us" > ~/.keyboard exit fi
To use this, you need to create the .keyboard file. So open up a terminal and type in
echo "us" > .keyboard
To use this for more than two layouts, you would add another RETURN variable (like RETURN2) and test for equality with another of your keymaps. Then, you'd add some more test statements checking first if RETURN is true, and then if RETURN2 is true. If neither is true, you should switch to the third layout.
Now just bind this script to a keyboard shortcut in Openbox and you're good to go!
Last edited by chaanakya (2011-01-10 21:34:23)
Or you could just put something like this in /etc/default/keyboard:
XKBMODEL="pc105" XKBLAYOUT="us,us intl" XKBVARIANT="" XKBOPTIONS="grp:switch,grp:alt_shift_toggle"
This allows you to change between layouts like in Windows, by pressing Alt+Right_Shift.
Last edited by chaanakya (2011-01-10 22:21:46)
I'm assuming you can just change the
to change the keybinding?
Yes. You can find a list of options in the following file: /usr/share/X11/xkb/rules/base.lst.
Eh...oh well...at least I get the satisfaction of writing a script...
As for me I prefer this easier steps;
-go to autorun.sh (open box)
-add this line
## Start keyboard with 3 language mapping by Omen
setxkbmap -layout 'us,ua,ru' -option 'grp:alt_shift_toggle' &
lol...I wrote this script before I figured out there was such an option with setxkbmap
or the setxkbmap option
setxkbmap -layout "us,us intl"
didn't work for me.
I had to use this or the equivalent with setxkbmap -variant:
I know it's bad forum manners to answer such an old post, but I thought if I had to find this out, then it may be helpful to someone else.