Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to map scancodes to keycodes

I would like to learn how to map a USB keyboard in Fedora 20 using udev, so I picked a simple example to map 'a' to 'b' and 'b' to 'a'. To start, I ran lsusb and from the output I see the line:

Bus 006 Device 007: ID 04b3:3025 IBM Corp. NetVista Full Width Keyboard
Then I created the file /etc/udev/hwdb.d/60-custom-keyboard.hwdb
keyboard:usb:v*p*
 KEYBOARD_KEY_30=b
 KEYBOARD_KEY_48=a

To apply the changes I ran udevadm --debug hwdb --update, which confirms the file was read:

calling: hwdb
reading file '/usr/lib/udev/hwdb.d/20-OUI.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-acpi-vendor.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-bluetooth-vendor-product.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-pci-classes.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-pci-vendor-model.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-sane-backends.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-usb-classes.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-usb-vendor-model.hwdb'
reading file '/etc/udev/hwdb.d/60-custom-keyboard.hwdb'
reading file '/usr/lib/udev/hwdb.d/60-keyboard.hwdb'
=== trie in-memory ===
nodes:             3614840 bytes (   90371)
children arrays:   1445920 bytes (   90370)
values arrays:     1107088 bytes (   69193)
strings:           1324887 bytes
strings incoming:  3309765 bytes (  216269)
strings dedup'ed:  2042934 bytes (  158214)
=== trie on-disk ===
size:              6046879 bytes
header:                 80 bytes
nodes:             2168904 bytes (   90371)
child pointers:    1445920 bytes (   90370)
value pointers:    1107088 bytes (   69193)
string store:      1324887 bytes
strings start:     4721992

When I unplug the keyboard and plug it back in and run udevadm --debug hwdb --test=keyboard:usb:v04B3p3025*, it seems to confirm the rules are in place:

=== trie on-disk ===
tool version:          208
file size:         6046879 bytes
header size             80 bytes
strings            1324887 bytes
nodes              4721912 bytes
KEYBOARD_KEY_30=b
KEYBOARD_KEY_48=a

However, pressing 'a' still yields 'a' and pressing 'b' still yieds 'b', and evtest shows no changes to the codes received. Rebooting did not make it happen either.

Could anyone please tell me what I am missing, or make a suggestion as to any other commands to troubleshoot what is going on?

How to map scancodes to keycodes

I would like to learn how to map a USB keyboard in Fedora 20 using udev, so I picked a simple example to map 'a' to 'b' and 'b' to 'a'. To start, I ran lsusb and from the output I see the line:

Bus 006 Device 007: ID 04b3:3025 IBM Corp. NetVista Full Width Keyboard
Then I created the file /etc/udev/hwdb.d/60-custom-keyboard.hwdb
keyboard:usb:v*p*
 KEYBOARD_KEY_30=b
 KEYBOARD_KEY_48=a
KEYBOARD_KEY_1e=b
 KEYBOARD_KEY_30=a

To apply the changes I ran udevadm --debug hwdb --update, which confirms the file was read:

calling: hwdb
reading file '/usr/lib/udev/hwdb.d/20-OUI.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-acpi-vendor.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-bluetooth-vendor-product.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-pci-classes.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-pci-vendor-model.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-sane-backends.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-usb-classes.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-usb-vendor-model.hwdb'
reading file '/etc/udev/hwdb.d/60-custom-keyboard.hwdb'
reading file '/usr/lib/udev/hwdb.d/60-keyboard.hwdb'
=== trie in-memory ===
nodes:             3614840 bytes (   90371)
children arrays:   1445920 bytes (   90370)
values arrays:     1107088 bytes (   69193)
strings:           1324887 bytes
strings incoming:  3309765 bytes (  216269)
strings dedup'ed:  2042934 bytes (  158214)
=== trie on-disk ===
size:              6046879 bytes
header:                 80 bytes
nodes:             2168904 bytes (   90371)
child pointers:    1445920 bytes (   90370)
value pointers:    1107088 bytes (   69193)
string store:      1324887 bytes
strings start:     4721992

When I unplug the keyboard and plug it back in and run udevadm --debug hwdb --test=keyboard:usb:v04B3p3025*, it seems to confirm the rules are in place:

=== trie on-disk ===
tool version:          208
file size:         6046879 bytes
header size             80 bytes
strings            1324887 bytes
nodes              4721912 bytes
KEYBOARD_KEY_30=b
KEYBOARD_KEY_48=a
KEYBOARD_KEY_1e=b
KEYBOARD_KEY_30=a

However, pressing 'a' still yields 'a' and pressing 'b' still yieds 'b', and evtest shows no changes to the codes received. Rebooting did not make it happen either.

Could anyone please tell me what I am missing, or make a suggestion as to any other commands to troubleshoot what is going on?

How to map scancodes to keycodes

I would like to learn how to map a USB keyboard in Fedora 20 using udev, so I picked a simple example to map 'a' to 'b' and 'b' to 'a'. To start, I ran lsusb and from the output I see the line:

Bus 006 Device 007: ID 04b3:3025 IBM Corp. NetVista Full Width Keyboard
Then I created the file /etc/udev/hwdb.d/60-custom-keyboard.hwdb/etc/udev/hwdb.d/99-custom-keyboard.hwdb
keyboard:usb:v*p*
 KEYBOARD_KEY_1e=b
 KEYBOARD_KEY_30=a

To apply the changes I ran udevadm --debug hwdb --update, which confirms the file was read:

calling: hwdb
reading file '/usr/lib/udev/hwdb.d/20-OUI.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-acpi-vendor.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-bluetooth-vendor-product.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-pci-classes.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-pci-vendor-model.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-sane-backends.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-usb-classes.hwdb'
reading file '/usr/lib/udev/hwdb.d/20-usb-vendor-model.hwdb'
reading file '/etc/udev/hwdb.d/60-custom-keyboard.hwdb'
reading file '/usr/lib/udev/hwdb.d/60-keyboard.hwdb'
reading file '/etc/udev/hwdb.d/99-custom-keyboard.hwdb'
=== trie in-memory ===
nodes:             3614840 bytes (   90371)
3614800 bytes (   90370)
children arrays:   1445920 bytes (   90370)
1445904 bytes (   90369)
values arrays:     1107088 bytes (   69193)
1107056 bytes (   69191)
strings:           1324887 1324895 bytes
strings incoming:  3309765 bytes (  216269)
3309755 bytes (  216264)
strings dedup'ed:  2042934 bytes (  158214)
2042916 bytes (  158209)
=== trie on-disk ===
size:              6046879 6046815 bytes
header:                 80 bytes
nodes:             2168904 bytes (   90371)
2168880 bytes (   90370)
child pointers:    1445920 bytes (   90370)
1445904 bytes (   90369)
value pointers:    1107088 bytes (   69193)
1107056 bytes (   69191)
string store:      1324887 1324895 bytes
strings start:     4721992
4721920

When I unplug the keyboard and plug it back in and run udevadm --debug hwdb --test=keyboard:usb:v04B3p3025*, it seems to confirm the rules are in place:

=== trie on-disk ===
tool version:          208
file size:         6046879 bytes
header size             80 bytes
strings            1324887 bytes
nodes              4721912 bytes
KEYBOARD_KEY_1e=b
KEYBOARD_KEY_30=a

However, pressing 'a' still yields 'a' and pressing 'b' still yieds 'b', and evtest shows no changes to the codes received. Rebooting did not make it happen either.

Could anyone please tell me what I am missing, or make a suggestion as to any other commands to troubleshoot what is going on?