Thursday, April 25, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 837  / 2 Years ago, mon, october 10, 2022, 5:38:41

I have a G7BTS remote controller, which has both keyboard and multimedia buttons. Most of its buttons work well except "OK" button.


The OK button has a keycode 353, which means KEY_SELECT. But my ubuntu 20.04 does not recognize it.


Below are some researches I have done:



  1. sudo evtest


output:


/dev/input/event9:  G7BTS Keyboard
/dev/input/event10: G7BTS Mouse
/dev/input/event11: G7BTS Consumer Control
/dev/input/event12: G7BTS System Control


  1. grep "" /sys/class/input/event11/device/id/*


output:


/sys/class/input/event11/device/id/bustype:0005
/sys/class/input/event11/device/id/product:0041
/sys/class/input/event11/device/id/vendor:045e
/sys/class/input/event11/device/id/version:0300


  1. sudo evtest /dev/input/event11


output:


Testing ... (interrupt to exit)
Event: time 1640250050.701930, type 4 (EV_MSC), code 4 (MSC_SCAN), value c0041
Event: time 1640250050.701930, type 1 (EV_KEY), code 353 (KEY_SELECT), value 1
Event: time 1640250050.701930, -------------- SYN_REPORT ------------


  1. /etc/udev/hwdb.d/60-keyboard.hwdb


I tried to remap OK button to 'enter'.


60-keyboard.hwdb file content:


# G7BTS
evdev:input:b0005v045Ep0041*
KEYBOARD_KEY_c0041=enter


  1. sudo udevadm hwdb --test='evdev:input:b0005v045ep0041*'


output:


KEYBOARD_KEY_c0041=enter

So far, I still cannot see any output in xev when I press OK button.


Any suggestions and help will be appreciated.


More From » keyboard

 Answers
7

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>-<modalias>

where <bus_id>, <vendor_id> and <version_id> 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.


[#914] Monday, October 10, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
singerrupt

Total Points: 435
Total Questions: 111
Total Answers: 109

Location: Angola
Member since Tue, May 5, 2020
4 Years ago
;