I normally work on laptop with a secondary usb keyboard. My fingers are used to laptop keyboard but when it comes to usb keyboard they some time has different keys layout so its hard to find home/end/pageup page down buttons and here starts the frustration.
We have several ways in linux to swap keys or remap keys of keyboard but there is no way to change it for the secondary or usb keyboard, but luckily we have an application that can change or remap your keyboard keys for multiple keyboards, that is “xkbcomp”.
You can use “xkbcomp” to remap keys of your external keyboards.
before using “xkbcomp” you must know the device id of your secondary keyboard.
Run following command to list your input devices
and look for
USB USB Keyboard id=15 [slave keyboard (3)]
Note the device id “15”
Now export current layout of your keyboard into a .xkb file, note the “-i 15”
“-i” tells xkbcomp to look for a device id and “15” is the id of your device.
$ xkbcomp -i 15 $DISPLAY ~/myusbkblayout.xkb
Edit the file generated by xkbcomp
$ nano ~/myusbkblayout.xkb
Change key codes ans save the file
For example my home and insert keys maps are as follow in output file
<HOME> = 110; <UP> = 111; <PGUP> = 112; <LEFT> = 113; <RGHT> = 114; <END> = 115; <DOWN> = 116; <PGDN> = 117; <INS> = 118;
and I want to swap Home and Insert buttons then I will just change codes against map like below
<INS> = 110; <UP> = 111; <PGUP> = 112; <LEFT> = 113; <RGHT> = 114; <END> = 115; <DOWN> = 116; <PGDN> = 117; <HOME> = 118;
Now we are going to upload keyboard layout file back to linux so it can adopt it
$ xkbcomp -i 15 ~/myusbkblayout.xkb $DISPLAY
Your second keyboard should be working as you want in few seconds.
For more info please look at official arch linux wiki