27

I want to connect two keyboard sets to my computer. Is it possible to set each for a specific language. So that there's no need to change language each time.

For example:

  • keyboard 1 types russian

  • keyboard 2 types english

2 Answers2

26

Using xinput and setxkbmap utilities, you can set from terminal so that each keyboard to have a different layout.

First, using xinput -list | grep key command, you have to find the device ID of each keyboard. Here s an example (my case):

$ xinput -list | grep key
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Power Button                              id=8    [slave  keyboard (3)]
    ↳ Sleep Button                              id=9    [slave  keyboard (3)]
    ↳ 2.4GHz 2way RF Receiver                   id=10   [slave  keyboard (3)]
    ↳ HP Webcam                                 id=12   [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=13   [slave  keyboard (3)]
    ↳ HP WMI hotkeys                            id=15   [slave  keyboard (3)]
    ↳   USB Keyboard                            id=16   [slave  keyboard (3)]
    ↳   USB Keyboard                            id=17   [slave  keyboard (3)]

And second, using setxkbmap -device <key_ID> -layout <layout_name>, set the layout which you wish for each keyboard. An example (for my keyboards):

setxkbmap -device 3 -layout ro    #My master keyboard is set to Romanian layout
setxkbmap -device 10 -layout us   #The keyboard with id=10 is set to English (US) layout
setxkbmap -device 16 -layout ru   #The keyboard with id=16 is set to EFor Russian layout
Radu Rădeanu
  • 169,590
  • 1
    Great. Works. Thanks. Maybe a separate question. But is there any way to monitor them in Plasma Desktop with some icon showing layout for each keyboard?! – Minimus Heximus Aug 26 '13 at 09:54
  • @MinimusHeximus It's a separate question, and I think that a simple answer in a comment to your question is hard to be done. So, please use the ask question button. – Radu Rădeanu Aug 26 '13 at 10:02
  • thanks. I may ask, but to be informative: now the normal language icon is completely irresposive in Plasma. btw, a solution in unity is welcome (which I have not tested yet). – Minimus Heximus Aug 26 '13 at 10:06
  • 1
    @MinimusHeximus Well, this solution should work in any Ubuntu Desktop. And I tested on Unity. – Radu Rădeanu Aug 26 '13 at 10:19
  • 3
    Thanks for this answer, which inspired me to ask a related question: How to permanently assign a different keyboard layout to a USB keyboard? It seems I'll need a startup script for this. First xinput -list | grep "USB Keyboard" will give me to device IDs (different at each startup). I need another command to cut the first ID number and then use it here: setxkbmap -device -layout – Sadi Aug 26 '13 at 10:50
  • Thanks! Any idea how to do this in the /etc/default/keyboard configuration file (or other config file)? This will probably do it: https://askubuntu.com/a/337431/42720 – Peter Becich Aug 01 '17 at 00:36
  • What's the point in setting device #3? Wouldn't #10 and #16 be enough? To which keyboards are #3 applied? – Torben Gundtofte-Bruun Jan 06 '19 at 20:42
7

Slightly off-topic, but if you additionally use the -variant option, you can type dvorak on one keyboard and workman or qwerty or any other layout on the other keyboard.

setxkbmap -verbose -device 17 -layout us -variant dvorak

Pair programming on steroids!

Ronald
  • 171