Score:4

Gnome Tweak Tools keyboard layout options - set only for Bluetooth keyboard?

cn flag

I have this helpful setting enabled in Tweak Tools when I use an annoying external Apple magic keyboard:

enter image description here

This setting makes the keyboard function in my view normal (super key is to the right of the control key).

However, this setting in tweak tool also affect my laptop own keymap. Can I somehow make this setting only for this annoying external Apple magic keyboard?

Artur Meinild avatar
vn flag
I'm assuming the solution here could be to make a hotkey that would easily switch the setting, maybe by changing the underlying config file. However, I'm not using Ubuntu Desktop myself, so don't know much about it, unfortunately.
nammerkage avatar
cn flag
It's a good approach @ArturMeinild, will try this If I don't find any automatic way.
vn flag
Did you try [this](https://unix.stackexchange.com/a/226641/209677) or [this](https://superuser.com/a/1190742/500826) answers related to [hid_apple module](https://wiki.archlinux.org/title/Apple_Keyboard#Switching_Cmd_and_Alt/AltGr)?
Score:1

You could use xkbcomp, and the detailed process is described here. You have to find the codes for the keys to be remapped. Other answers in the same OP might be useful.

xkeycaps may come in handy.

Related>

  1. How do I remap certain keys or devices?
  2. https://dev.to/0xbf/remap-keys-in-the-keyboard-in-ubuntu-5a36
  3. http://www.fascinatingcaptain.com/projects/remap-keyboard-keys-for-ubuntu/
  4. (In comment by Pablo Bianchi) https://superuser.com/questions/277990/how-do-i-swap-alt-and-windows-keys-with-xmodmap
  5. (In comment by Pablo Bianchi) https://unix.stackexchange.com/questions/86933/swap-alt-and-super
nammerkage avatar
cn flag
Thank you very much the for help. My coworker had a solution which could works exactly like [one of the links you gave](https://superuser.com/a/1398289/1147657)
sancho.s ReinstateMonicaCellio avatar
@nammerkage - Glad it worked for you! In addition to the detailed answer posted, it is good that you provide feedback in the other link.
Score:1
cn flag

This, as a whole, is a s#!^ answer, because of its lack of completeness, but I would just assign the key swap option to the specific keyboard with setxkbmap.

xinput will give you the id of your keyboard

wutang@shaolin:~$ xinput

⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ VirtualBox mouse integration              id=9    [slave  pointer  (2)]
⎜   ↳ VirtualBox USB Tablet                     id=10   [slave  pointer  (2)]
⎜   ↳ ImExPS/2 Generic Explorer Mouse           id=12   [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)]
    ↳ Sleep Button                              id=7    [slave  keyboard (3)]
    ↳ Video Bus                                 id=8    [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=11   [slave  keyboard (3)]

full disclosure I am being extremely lazy and not disturbing my virtual to pass the second keyboard I have tested with, and even more lazy not setting up to cut & paste from host(-->VM) that actually does show the 2 keyboards...(s#!^ answer)
so you just have to imagine that there is a second keyboard in my output with a unique id

If I am going to only alter one of my keyboards (AT Translated Set 2 keyboard):
setxkbmap -device 11 -option altwin:swap_lalt_lwin

I am going to assume that this is not permanent; probably goes away if you unplug the keyboard, logout, or power off.

The -option flag without providing an option, removes all options.

nammerkage avatar
cn flag
Thanks for your comment @WU-Tang. But for me `xinput` doesn't easily show which keyboard I should use. Could it be "xwayland-keyboard:18" Is that an apple keyboard? I made a solution to this post, by following my coworkers tips
WU-TANG avatar
cn flag
@nammerkage all you would have to do is unplug the keyboard in question and use process of elimination...
Score:0
cn flag

Turns out my coworker had the same issue. With his permission here's the solution that worked right away:

First run this and scroll to the information about the keyboard Run cat /proc/bus/input/devices | less

I: Bus=0005 Vendor=004c Product=026c Version=0160
N: Name="Magic Keyboard with Numeric Keypad"
P: Phys=44:e5:17:96:76:24
S: Sysfs=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:004C:026C.0007/input/input38
U: Uniq=c4:14:11:03:c2:de
H: Handlers=sysrq kbd event20 leds 
B: PROP=0
B: EV=120013
B: KEY=10000 0 0 1 1007b00001007 ff9f207ac14057ff ffbeffdfffefffff fffffffffffffffe
B: MSC=10
B: LED=1f

Now construct an id via this way:

evdev:input:b<bus_id>v<vendor_id>p<product_id>e<version_id>-<modalias>

Where version and modalies don't matter. I get this:

evdev:input:b0005v004Cp026C*

Next create this file

etc/udev/hwdb.d/60-applekeyboard.hwdb

I don't think the name matters but I am not sure.

The file should contain the ID we just made and the remap of keys:

# Apple magic
evdev:input:b0005v004Cp026C*
 KEYBOARD_KEY_700e2=leftmeta
 KEYBOARD_KEY_700e3=leftalt

How do you find the names? just execute sudo evtest find your keyboard and press the key you want to chage.. Output looks like this:

Event: time 1644400418.762658, type 4 (EV_MSC), code 4 (MSC_SCAN), value 700e3
Event: time 1644400418.762658, type 1 (EV_KEY), code 56 (KEY_LEFTMETA), value 1

Use that output to construct the desired key and change.

Next, sudo run these commands to update:

systemd-hwdb update
udevadm control --reload-rules
udevadm trigger

Then you are done.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.