5

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?

N0rbert
  • 99,918
nammerkage
  • 147
  • 10

3 Answers3

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
1

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.

WU-TANG
  • 3,071
  • 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 – nammerkage Feb 03 '22 at 07:52
  • @nammerkage all you would have to do is unplug the keyboard in question and use process of elimination... – WU-TANG Feb 03 '22 at 15:12
0

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.

nammerkage
  • 147
  • 10