SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2011-01-10 21:24:53

chaanakya
#! Die Hard
Registered: 2010-12-30
Posts: 940

Switching Keyboard Layouts - the EASY way!

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

That's it!

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! smile

Last edited by chaanakya (2011-01-10 21:34:23)


Check out Musik - an easy-to-use text-to-music converter!
Join SpiderOak using this link and get an extra 1 GB free: https://spideroak.com/download/referral … 660e787ff1

Offline

Help fund CrunchBang, donate to the project!

#2 2011-01-10 22:06:08

afita
New Member
Registered: 2011-01-08
Posts: 3

Re: Switching Keyboard Layouts - the EASY way!

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.

Offline

#3 2011-01-10 22:21:35

chaanakya
#! Die Hard
Registered: 2010-12-30
Posts: 940

Re: Switching Keyboard Layouts - the EASY way!

Oh... tongue  lol big_smile

Last edited by chaanakya (2011-01-10 22:21:46)


Check out Musik - an easy-to-use text-to-music converter!
Join SpiderOak using this link and get an extra 1 GB free: https://spideroak.com/download/referral … 660e787ff1

Offline

#4 2011-01-10 22:22:45

chaanakya
#! Die Hard
Registered: 2010-12-30
Posts: 940

Re: Switching Keyboard Layouts - the EASY way!

I'm assuming you can just change the

alt_shift_toggle

to change the keybinding?


Check out Musik - an easy-to-use text-to-music converter!
Join SpiderOak using this link and get an extra 1 GB free: https://spideroak.com/download/referral … 660e787ff1

Offline

#5 2011-01-10 23:24:22

afita
New Member
Registered: 2011-01-08
Posts: 3

Re: Switching Keyboard Layouts - the EASY way!

Yes. You can find a list of options in the following file: /usr/share/X11/xkb/rules/base.lst.

Offline

#6 2011-01-11 01:35:44

chaanakya
#! Die Hard
Registered: 2010-12-30
Posts: 940

Re: Switching Keyboard Layouts - the EASY way!

Eh...oh well...at least I get the satisfaction of writing a script... wink


Check out Musik - an easy-to-use text-to-music converter!
Join SpiderOak using this link and get an extra 1 GB free: https://spideroak.com/download/referral … 660e787ff1

Offline

#7 2011-01-17 21:22:06

omen
Member
Registered: 2011-01-17
Posts: 12

Re: Switching Keyboard Layouts - the EASY way!

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' &

That`s all.

Offline

#8 2011-01-18 01:39:41

chaanakya
#! Die Hard
Registered: 2010-12-30
Posts: 940

Re: Switching Keyboard Layouts - the EASY way!

lol...I wrote this script before I figured out there was such an option with setxkbmap big_smile


Check out Musik - an easy-to-use text-to-music converter!
Join SpiderOak using this link and get an extra 1 GB free: https://spideroak.com/download/referral … 660e787ff1

Offline

#9 2013-11-24 14:53:00

valmi
New Member
Registered: 2013-11-24
Posts: 1

Re: Switching Keyboard Layouts - the EASY way!

Using either

XKBLAYOUT="us,us intl"

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:

XKBLAYOUT="us,us"
XKBVARIANT=",intl"

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.

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo