Monday, August 7, 2017

Separate keyboard for shortcuts on linux (two keyboards,two layouts)


I have two keyboards: an old ps/2 one and a usb one. I want the usb keyboard to have the us layout (or prefferably have the usb keyboard follow the layout chosen in gnome) and the ps/2 one to have a custom layout (shortcuts and other things :D). I've tried to set seperate layouts on each keyboard at runtime using setxkbmap -device 8 -layout ru (russian layout to test), but this sets the layout on all keyboards to russian.


philippe@tnw:~$ xinput -list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ MOSART Semi. Wireless Keyboard & Mouse id=9 [slave pointer (2)]
⎜ ↳ Logitech USB Receiver id=10 [slave pointer (2)]
⎜ ↳ Logitech USB Receiver id=11 [slave pointer (2)]
⎣ 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)]
↳ MOSART Semi. Wireless Keyboard & Mouse id=8 [slave keyboard (3)]
↳ Eee PC WMI hotkeys id=12 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=13 [slave keyboard (3)]

Edit:
Found the part of the answer:
When you specify the layout for a device, you have to include all the layouts you want on all the hardware. So if I want russian on device 2 and US english on 3 then I need to use "ru,us" when specifiying the layout for device 2 and us,ru for device 3. Like this


setxkbmap -device 2 -layout ru,us
setxkbmap -device 3 -layout us,ru

I still need to get this on startup and make a custom layout. Help with that would be much appreciated.


Answer



You need to use



xinput --create-master SecondKeyboard



to create a separate master keyboard, and then reattach the second keyboard to the new master:



xinput --reattach "Keyboard Id" "Master Id"



You use the ids from



xinput --list



This way the keyboards are separate and can be treated exclusively. E.g. you have two focuses, you can write in two applications at the same time with two keyboards, and set different key mappings, by specifying different master ids in things like setxkbmap.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...