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