Ask Your Question

How to map scancodes to keycodes

asked 2014-05-02 18:37:41 +0000

ed gravatar image

updated 2014-05-02 20:55:39 +0000

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/99-custom-keyboard.hwdb

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 '/usr/lib/udev/hwdb.d/60-keyboard.hwdb'
reading file '/etc/udev/hwdb.d/99-custom-keyboard.hwdb'
=== trie in-memory ===
nodes:             3614800 bytes (   90370)
children arrays:   1445904 bytes (   90369)
values arrays:     1107056 bytes (   69191)
strings:           1324895 bytes
strings incoming:  3309755 bytes (  216264)
strings dedup'ed:  2042916 bytes (  158209)
=== trie on-disk ===
size:              6046815 bytes
header:                 80 bytes
nodes:             2168880 bytes (   90370)
child pointers:    1445904 bytes (   90369)
value pointers:    1107056 bytes (   69191)
string store:      1324895 bytes
strings start:     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

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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-05-07 00:24:53 +0000

ed gravatar image

updated 2014-05-07 00:25:32 +0000

The correct hwdb mappings from key 'a' to key 'b' and vice-versa for an USB keyboard are:


The scan codes for an USB keyboard are *NOT* what the showkey -s command reveals. Instead, they can be found from the evtest command (see the 'value' field):

Event: time 1399420905.069693, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70004
Event: time 1399420905.069693, type 1 (EV_KEY), code 30 (KEY_A), value 1
Event: time 1399420905.069693, -------------- SYN_REPORT ------------
aEvent: time 1399420905.181691, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70004
Event: time 1399420905.181691, type 1 (EV_KEY), code 30 (KEY_A), value 0
Event: time 1399420905.181691, -------------- SYN_REPORT ------------
Event: time 1399420910.525751, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70005
Event: time 1399420910.525751, type 1 (EV_KEY), code 48 (KEY_B), value 1
Event: time 1399420910.525751, -------------- SYN_REPORT ------------
bEvent: time 1399420910.605743, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70005
Event: time 1399420910.605743, type 1 (EV_KEY), code 48 (KEY_B), value 0
Event: time 1399420910.605743, -------------- SYN_REPORT ------------
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Use your votes!

  • Use the 30 daily voting points that you get!
  • Up-vote well framed questions that provide enough information to enable people provide answers.
  • Thank your helpers by up-voting their comments and answers. If a question you asked has been answered, accept the best answer by clicking on the checkbox on the left side of the answer.
  • Down-voting might cost you karma, but you should consider doing so for incorrect or clearly detrimental questions and answers.

Question Tools

1 follower


Asked: 2014-05-02 18:37:41 +0000

Seen: 2,670 times

Last updated: May 07 '14