4

I'm using Gnome Tweaks "additional layout options" to customise the placement of my modifier keys so that they're usable for my keyboard layout. I would like my left Win and left Ctrl to switch places on my internal laptop keyboard only, but not for my external USB keyboards.

How do I accomplish this?

Background: The default placement of 3rd level modifier keys is very unergonomically placed on my Macbook Air keyboard, but not necessarily on external keyboards. This situation requires layout options to be customised per keyboard.


As a side note I should mention that macOS currently recognizes this need adequately by offering arbitrary remapping of the modifier keys on the internal keyboard, while Windows has practically no similar feature at all without resorting to third party tools like SharpKeys.

1
  • 1
    Very relevant question. I think this is not easily possible, but let us see what answers come.
    – vanadium
    Nov 2, 2020 at 17:26

1 Answer 1

2

This can be achieved at hardware level change, So undo the changes you have done via gnome-tweaks. Requires root privileges.

Reference: https://manpages.ubuntu.com/manpages/focal/man7/hwdb.7.html

Note: If any of the packages are found "not installed" while doing this, install them.

Example:

run sudo evtest

[admin@ADMIN ~]$ sudo evtest
[sudo] password for admin: 
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0:  Power Button
/dev/input/event1:  Lid Switch
/dev/input/event2:  Power Button
/dev/input/event3:  AT Translated Set 2 keyboard
/dev/input/event4:  Compx 2.4G Receiver
/dev/input/event5:  Compx 2.4G Receiver
/dev/input/event6:  Compx 2.4G Receiver System Control
/dev/input/event7:  Compx 2.4G Receiver Consumer Control
/dev/input/event8:  Toshiba input device
/dev/input/event9:  PC Speaker
/dev/input/event10: Video Bus
/dev/input/event11: Video Bus
/dev/input/event12: ETPS/2 Elantech Touchpad
/dev/input/event13: HDA Intel PCH Mic
/dev/input/event14: HDA Intel PCH Headphone
/dev/input/event15: HDA Intel PCH HDMI/DP,pcm=3
/dev/input/event16: HDA Intel PCH HDMI/DP,pcm=7
/dev/input/event17: HDA Intel PCH HDMI/DP,pcm=8
/dev/input/event18: HDA Intel PCH HDMI/DP,pcm=9
/dev/input/event19: HDA Intel PCH HDMI/DP,pcm=10
Select the device event number [0-19]: 

from the above output event3 is my Toshiba Laptops inbuilt keyboard and damaged. event4 is my wireless keyboard. I am going to configure this wireless keyboard only to swap Left Win and Left Control.

from the above output prompt, Choose 4 as this is my wireless keyboard. and then Press both the Keys, Left Control and Left Windows.. They are identified as below (some of the output only)

Event: time 1604846371.179388, -------------- SYN_REPORT ------------
Event: time 1604846371.269377, type 4 (EV_MSC), code 4 (MSC_SCAN), value 700e0
Event: time 1604846371.269377, type 1 (EV_KEY), code 29 (KEY_LEFTCTRL), value 0
Event: time 1604846371.269377, -------------- SYN_REPORT ------------
Event: time 1604846375.626511, type 4 (EV_MSC), code 4 (MSC_SCAN), value 700e3
Event: time 1604846375.626511, type 1 (EV_KEY), code 125 (KEY_LEFTMETA), value 1
Event: time 1604846375.626511, -------------- SYN_REPORT ------------

Note down the values and Keynames as below

value 700e0, Keyname LEFTCTRL
value 700e3, Keyname LEFTMETA

So for swapping we need 700e0 as leftmeta ( note, small letters are needed against capital letters in above output) and
700e3 as leftctrl

Now Open the file with below command, replace eventX with your keyboard eventNumber.

sudo -H gedit /sys/class/input/event4/device/modalias

Example Contents for my use case,

input:b0003v1D57pFA20e0100-e0,1,4,11,14,k71,72,73,74,75,77,79,7A,7B,7C,7D,7E,7F,80,81,82,83,84,85,86,87,88,89,8A,B7,B8,B9,BA,BB,BC,BD,BE,BF,C0,C1,C2,F0,ram4,l0,1,2,sfw

Note the above text from the modalias file.

Now create the hwdb config file and open it with below command

sudo -H gedit /etc/udev/hwdb.d/10-my-modifiers.hwdb

this file should have below content, based on above workout..

evdev:input:b0003v1D57pFA20e0100-e0,1,4,11,14,k71,72,73,74,75,77,79,7A,7B,7C,7D,7E,7F,80,81,82,83,84,85,86,87,88,89,8A,B7,B8,B9,BA,BB,BC,BD,BE,BF,C0,C1,C2,F0,ram4,l0,1,2,sfw
 KEYBOARD_KEY_700e3=leftctrl
 KEYBOARD_KEY_700e0=leftmeta

Save the File & Close.

We have configured the file. update the hwdb with below command.

sudo systemd-hwdb update

If no errors are shown, good to go. Otherwise we need to look for evdev line to configure properly.

to apply the changes immediately, run the below command.

sudo udevadm trigger

Tested with Two Wireless Keyboards With Different Configs.. Both proved for individuality.

Major Reference: https://wiki.archlinux.org/index.php/Map_scancodes_to_keycodes
A Similar One: How to remap 'Caps_Lock' key to 'w' in Wayland

1
  • Worked for me. Thanks for writing this up. Jul 8, 2021 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.