Thanks everyone.
It took me several days to find out the solution, finally, I found the right way.
Reference
Map scancodes to keycodes
Background
Version 11 of the X protocol only supports single-byte key codes. So key codes above 255 are ignored. Ubuntu 20.04 LTS, so far, still uses version 11 of X protocol.
My G7BTS remote keyboard has a “OK” button. This button has a key code of 353. Within “xev”, nothing happens when this button is pressed.
Solution
By brief, the solution is to create a hwdb configuration file, which is used to remap certain keys to other keys.
udev
udev provides a builtin function called hwdb to maintain the hardware database index in /etc/udev/hwdb.bin. The database is compiled from files with .hwdb extension located in directories /usr/lib/udev/hwdb.d/, /run/udev/hwdb.d/ and /etc/udev/hwdb.d/. The default scancodes-to-keycodes mapping file is /usr/lib/udev/hwdb.d/60-keyboard.hwdb.
Generic input devices (also USB keyboards) identified by the usb kernel modalias:
evdev:input:b<bus_id>v<vendor_id>p<product_id>e<version_id>-
where , and are the 4-digit hex uppercase vendor, product and version IDs
How to find those ids above is the key
install hardinfo
sudo apt install hardinfo
software – System Profiler – Input Devices – G7BTS Comsumer Control
Device Information
Name G7BTS Comsumer Control
Type keyboard
Bus 0x0005
Vender 0x045e
Product 0x0041
Version 0x0300
Another import thing is to get the scan code of the “OK” button.
install evtest
sudo apt-get install evtest
sudo evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0: Lid Switch
/dev/input/event1: Sleep Button
/dev/input/event2: Power Button
/dev/input/event3: AT Translated Set 2 keyboard
/dev/input/event4: SynPS/2 Synaptics TouchPad
/dev/input/event5: TPPS/2 IBM TrackPoint
/dev/input/event6: ThinkPad Extra Buttons
/dev/input/event7: Video Bus
/dev/input/event8: Integrated Camera: Integrated C
/dev/input/event9: G7BTS Keyboard
/dev/input/event10: G7BTS Mouse
/dev/input/event11: G7BTS Consumer Control
/dev/input/event12: G7BTS System Control
/dev/input/event13: HDA Intel PCH Mic
/dev/input/event14: HDA Intel PCH Dock Mic
/dev/input/event15: HDA Intel PCH Headphone
/dev/input/event16: HDA Intel PCH Dock Headphone
/dev/input/event17: HDA Intel PCH HDMI/DP,pcm=3
/dev/input/event11: HDA Intel PCH HDMI/DP,pcm=7
/dev/input/event19: HDA Intel PCH HDMI/DP,pcm=8
Select the device event number [0-19]: ^C
Pay attention to “/dev/input/event11”
sudo evtest /dev/input/event11
Then press “OK” button, and the output is below
Event: time 1640238746.775220, type 4 (EV_MSC), code 4 (MSC_SCAN), value c0041
Event: time 1640238746.775220, type 1 (EV_KEY), code 353 (KEY_SELECT), value 0
Event: time 1640238746.775220, -------------- SYN_REPORT ------------
Pay attention to “value c0041“. This value c0041 is the scan code of “OK” button.
Make the hwdb file
Now, we have the ids and the scan code we need. Put them into the “Generic input devices (also USB keyboards) identified by the usb kernel modalias” above, and finally we have the configuration file G7BTS.hwdb below:
evdev:input:b0005v045Ep0041e0300*
KEYBOARD_KEY_c0041=enter
In the context, the “OK” button is mapped into “enter” key. You can map it into any key you want.
Put file to destination
sudo mv G7BTS.hwdb /etc/udev/hwdb.d/
Update
sudo udevadm hwdb --update
sudo udevadm trigger --verbose
Test
sudo udevadm hwdb --test='evdev:input:b0005v045Ep0041e0300*'
result is
KEYBOARD_KEY_c0041=enter
The End
That is all the steps to remap keys. Those remapping still work after reboot.