Linux – Two keyboards on one computer. When I write with A I want a US keyboard layout, when I use B I want Swedish. Possible

input-languageskeyboardkeyboard-layoutlinux

I have a laptop which I use an external keyboard with. When I type using the external keyboard I want to use a US keyboard layout, since that's the type of external keyboard I have. On the other hand, when I type using the integrated keyboard I'd like to use a Swedish layout.

Is this possible? And how would I go about doing it?

I'm asking here as I think we'll find most Linux expertise here.

Best Answer

First, you have to find the device ID of the keyboard to change:

$ xinput -list | grep -i 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)]
    ↳ Power Button                              id=7    [slave  keyboard (3)]
    ↳ LITEON Technology USB Keyboard            id=9    [slave  keyboard (3)]
    ↳ LITEON Technology USB Keyboard            id=10   [slave  keyboard (3)]

Then change the layout using setxkbmap:

$ setxkbmap -device 9 dvorak

Some versions of setxkbmap need a '-layout' argument:

$ setxkbmap -device 9 -layout dvorak
Related Question