# The Ubuntu Forum Community > Ubuntu Official Flavours Support > Desktop Environments > [lubuntu] lubuntu/lxde keyboard layout switching?

## michael.conner

I'm using lubuntu 10.04 beta 2. I've read wikis on xkb and various other topics related to switching keyboard layouts _without_ the use of a dedicated applet (as lxde doesn't seem to yet have one) and really cannot figure out how to set up keyboard layout switching.

I want to be able to switch keyboard layouts between English and German while holding down the CAPSLOCK key -- in other words, just for typing German characters such as ö, ä, ü, and ß. I don't want to switch completely to the German keyboard. 

The solution I'm using right now works and is somewhat inelegant: I installed xfce4-panel and xfce4-xkb-plugin, started xfce4-panel, added the keyboard layouts plugin, then removed everything BUT the keyboard layout plugin, set it to "normal width" and "auto-hide." So it just hangs out on the very margin of my screen and lets me switch keyboard layouts like I want to do.

Is there an easier way to do this natively without using the xfce4 panel? Granted, it's not like a little xfce4 applet takes up a lot of memory.

----------


## mikewhatever

I've used lxde last summer, not Lubuntu though, and the following worked for switching layouts.
http://ubuntuforums.org/showthread.php?t=1039107

It's not quite what you want, but a short in the right direction.

----------


## michael.conner

> I've used lxde last summer, not Lubuntu though, and the following worked for switching layouts.
> http://ubuntuforums.org/showthread.php?t=1039107
> 
> It's not quite what you want, but a short in the right direction.


Thanks... I'd seen that one, couldn't really figure out how to get there from here, if you know what I mean. I ended up just doing a minimal netboot install and installed a "minimal-enough" XFCE desktop for my purposes.

----------


## mikewhatever

> Thanks... I'd seen that one, couldn't really figure out how to get there from here, if you know what I mean. I ended up just doing a minimal netboot install and installed a "minimal-enough" XFCE desktop for my purposes.


Should have PM`ed me for clarifications, anyway, hope you're enjoying xfce minimal.
I've been testing Lubuntu-10.04 in a Virtual Box today, and there is still no straightforward way to switch keyboard layouts. Apparently, after issuing the following command switching English and Hebrew layouts worked:



```
setxkbmap -option grp:ctrl_shift_toggle "us,il"
```

Just some notes:
I used Ctrl_Shift and not Alt_Shift, because the latter was set too, and switched keyboard layouts on the host machine.
The layout setting survived several virtual machine restarts.
Found another way, but it didn't work.

----------


## Dreiggy

> Should have PM`ed me for clarifications, anyway, hope you're enjoying xfce minimal.
> I've been testing Lubuntu-10.04 in a Virtual Box today, and there is still no straightforward way to switch keyboard layouts. Apparently, after issuing the following command switching English and Hebrew layouts worked:
> 
> 
> 
> ```
> setxkbmap -option grp:ctrl_shift_toggle us,il
> ```
> 
> ...


but this dont work after system restarting... Maybe is better way?

----------


## 3Miro

You can make that into a script that runs as a startup application. It is a bit more involved in LXDE than say Gnome, but it can be done. Try finding documentation about startup applications under LXDE.

----------


## GrouchyGaijin

I use a really cool utility called Auto Key to paste in phrases I often use, like my email address or home address.
The problem is that Auto Key doesn't recognize when I switch keyboard layouts using the panel applet. This results in the ä in my address, for example, being dropped.

I need to use setxkbmap

I can type setxkbmap us or setxkbmap se in a terminal window to change the layouts, but I'd realy like to have a hot key or launcher to do this. How can I set up a hot key or launcher to run the setxkbmap command?

I know it involves a Bash file, but I'm lost as to the specifics.
I'm running Gnome in Ubuntu 10.10

I also noticed that if I just use setxkbmp us all the characters above the number keys (! @ etc) stop working.  Any ideas on what I need to change so that these work?



I'd appreciate any help.

----------


## nomnex

To add a keyboard layout using LXDE (change "jp" for your default, and "ch(fr)" for your second layout):



```
setxkbmap -layout "jp,ch(fr)" -option "grp:alt_shift_toggle"
```

Copy the command at the end of your /home/user/.bashrc file. The file is hidden by default. (see sample below)



```
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

# User specific aliases and functions

setxkbmap -layout "jp,ch(fr)" -option "grp:alt_shift_toggle"
```

Log-out/in.

----------


## mörgæs

Thanks Nomnex, it works fine. 

The method extends to more than two languages:



```
setxkbmap -layout "dk,is,fr" -option "grp:alt_shift_toggle"
```

----------


## hallboy3

open file /etc/default/keyboard and add necessary options:



```
XKBMODEL="pc105"
XKBLAYOUT="us,ua,ru"
XKBVARIANT=","
XKBOPTIONS="grp:ctrl_shift_toggle,grp_led:scroll"
```

than restart X session

----------


## jards

Thanks, nomnex, it works fine for me to.

----------


## TheStefan12345

> open file /etc/default/keyboard and add necessary options:
> 
> 
> 
> ```
> XKBMODEL="pc105"
> XKBLAYOUT="us,ua,ru"
> XKBVARIANT=","
> XKBOPTIONS="grp:ctrl_shift_toggle,grp_led:scroll"
> ...


How to put in both serbian cyrillic and serbian latin keyboards?

----------


## jablan

> How to put in both serbian cyrillic and serbian latin keyboards?


Try this way:



```
XKBMODEL="pc105"
XKBLAYOUT="us,rs,rs"
XKBVARIANT=",latin,"
XKBOPTIONS="grp:ctrl_shift_toggle,grp_led:scroll"
```

poz.

----------


## kvalvik01

Thank you nomnex and hallboy! Both your versions work well on my Lenovo S10-2 - until I switch off or reboot, that is. Although the inserted commands are still there (in bashrc, resp. in the keyboard-layout), alt_shift doesn't toggle the keyboard anymore.

Any advice? ty

upate:

I did both, now it works; my next problem is how to switch from latin script to hiragana, katakana and kanji in japanese - I installed anthy from the synaptic packet manager, but that hasn't had any effect so far

Any advice

----------


## Neosano

And the easiest solution is to add this line to /etc/xdg/lxsession/Lubuntu/autostart

@setxkbmap -option grp:alt_shift_toggle "us,ru"


so simply type this into your terminal and it's going to be ok after restart.


```
echo '@setxkbmap -option grp:alt_shift_toggle "us,ru"' | sudo tee -a /etc/xdg/lxsession/Lubuntu/autostart
```

----------


## absurdus_delirium

> And the easiest solution is to add this line to /etc/xdg/lxsession/Lubuntu/autostart
> 
> @setxkbmap -option grp:alt_shift_toggle "us,ru"
> 
> 
> so simply type this into your terminal and it's going to be ok after restart.
> 
> 
> ```
> ...


Thanks guys! Worked like a charm! I'm just posting this reply because when I first pasted the code into my terminal I didn't change the "us,ru" part so I ended up successfully toggling english and russian. Only problem is I am Greek! O_o
I tried re-entering the code with the proper changes but it didn't seem to matter. What I found out when I checked /etc/xdg/lxsession/Lubuntu/autostart was that each time I ran the code through the terminal a new line was added at the end of the file but it just ignored anything past the "us,ru" one. So, if you find yourself in the same situation, edit the file and leave just the part of the code you need. In my case it is 

```
@setxkbmap -option grp:ctrl_shift_toggle "us,gr"
```

 because I prefer switching with ctrl+shift.

----------


## nomnex

the easiest way it to use ibus input (you can set most languages and keyboards in the prefs.), else look at the arch wiki lxde, you will get all the answers, and more, along this thread.

there is a keyboard layout configuration on the way for lxde

---lxde list---
Gabriel thanks for your corrections. 

The main difference between lxkb-config and lxkeymap is that lxkeymap is wrote in python what makes it consume more resources. The version that you see is quite immature in fact it is just the version 0.1 by the next two weeks I will be working on it. 


TODO list: 
- Add test box to try the layouts 
- Upgrade the UI (not gtk 3 yet*) 
- Upgrade system integration (add .desktop file to the package) 
- Add "model selection" functionality 
- Add "options and shorcuts selection" functionality 
- Complete the package documentation (I need help here!) 

** I'm not going to take the application right now to gtk3 because the lxde desktop is not in GTK 3. But i will do it in the future. 

Greetings

----------


## dajare

I can get the keyboard "toggle" working well, using something like:



```
setxkbmap -option grp:switch,grp:alt_shift_toggle,grp_led:scroll gb,ar,ru
```

My questions: 
(1) how to set up a "hot-key" to *switch* (rather than "toggle") to a different keyboard layout?
(2) how to use "alt + [num]" combinations as the "hot-key"?

The scenario is having several (even many) different lang/kbds available  from the press of a key-combo. Using "toggle" to cycle through 5, 10, 15+  options is not realistic.

What I've found (in addition to this useful thread): for (1), a BodhiLinux forum thread with useful kbd toggling information; and for (2) some info on using xev to determine the keybinding name.

Unfortunately, when I use something like:



```
setxkbmap -option grp:switch,grp:alt_1_toggle gb
setxkbmap -option grp:switch,grp:alt_2_toggle ar
setxkbmap -option grp:switch,grp:alt_3_toggle ru

or

setxkbmap -option grp:switch,grp:alt_1_switch gb etc. ...
```

(or substitute "Alt_L" for "alt" in the lines above) (these are my best guesses), I don't get the switch action - perhaps because the hotkey combination isn't accessible in the new keyboard? Maybe?

I don't know! But I hope someone does. Thanks for any help with this!

*Bonus*: How nice would it be to have some means of displaying the current language/keyboard? (Answer: very nice!)

----------


## nomnex

> I can get the keyboard "toggle" working well, using something like:


I use Fedora. The path on Ubuntu might be different. For a list of all the options:

       /usr/share/X11/xkb/rules/xog.lst

----------


## dajare

> My questions: 
> (1) how to set up a "hot-key" to *switch* (rather than "toggle") to a different keyboard layout?
> (2) how to use "alt + [num]" combinations as the "hot-key"?


In doing a recent forum search, the "obkey" announcement came up as a hit. Does exactly what's need! Hope this is a help to others looking to use hotkeys to *switch* keyboard layouts rather than *toggle* them. Works for me!

----------


## nomnex

dajare, why don't you simply rely on ibus for your different input languages?

Ctrl + Space turns ibus on
Alt+Shift switches input languages

----------


## dajare

> dajare, why don't you simply rely on ibus for your different input languages?


Because I didn't know I could?  :Wink:  And in large part the point is _not_ to cycle through language options, but to be able to switch immediately to any one of a dozen or more possibilities.




> Ctrl + Space turns ibus on
> Alt+Shift switches input languages


And this appears to do nothing on my setup. Obviously I'm doing something wrong -- but hard to know what that might be!  :Confused: 

*Update:* That would be because ibus isn't installed. ...  :Roll Eyes (Sarcastic):  I'm still not sure it will do the any-to-any _switching_, though, as opposed to cycling through options. Can anyone confirm?

----------


## nomnex

> to switch immediately to any one of a dozen or more possibilities.


Do you need that many languages? You can use 4 different keyboard layouts in i-bus.




> I'm still not sure it will do the any-to-any _switching_, though, as opposed to cycling through options. Can anyone confirm?


You can define your shortcuts*. Or you can use your mouse, and left-click to change language.

* next/previous input language

----------


## paulkiss

> And the easiest solution is to add this line to /etc/xdg/lxsession/Lubuntu/autostart
> 
> @setxkbmap -option grp:alt_shift_toggle "us,ru"
> 
> 
> so simply type this into your terminal and it's going to be ok after restart.
> 
> 
> ```
> ...


Thanks, man, you saved me!

----------

