7

At first glance, it seems /usr/share/X11/xkb/keycodes/ contains the mapping of raw keycodes reported by the device, and 'showkey --scancodes` command can return the scancode. It's easy to think that they are the same thing.

But they are evidently different.showkeys -scancodes reliably returns the Linux Keycode, as in Linux Keycode Table converted to hex; while 'raw keycode' in xkb refer to are always different than the table.

Take the key 1 for example:

  • showkey --scancodes returns 0x02 as the keycode of 1
  • in xorg, the symblic name is <AE01>, which has 10 as its raw keycode, certainly not 0x02.

    $ grep AE01 /usr/share/X11/xkb/keycodes/evdev 
    &ltAE01> = 10;

So, for the purpose of configuring xkb, how to find the raw keycode for any key, given that showkey --scancodes is not suitable?

1 Answers1

5

The xev program will output the expected keycodes. For your example of 1:

KeyPress event, serial 37, synthetic NO, window 0x600001,
    root 0xd4, subw 0x0, time 6931965, (284,-10), root:(285,560),
    state 0x0, keycode 10 (keysym 0x31, 1), same_screen YES,
    XLookupString gives 1 bytes: (31) "1"
    XmbLookupString gives 1 bytes: (31) "1"
    XFilterEvent returns: False

KeyRelease event, serial 37, synthetic NO, window 0x600001,
    root 0xd4, subw 0x0, time 6932164, (284,-10), root:(285,560),
    state 0x0, keycode 10 (keysym 0x31, 1), same_screen YES,
    XLookupString gives 1 bytes: (31) "1"
    XFilterEvent returns: False
Stefan
  • 25,300
  • 4
    It turns out that in X and in Linux console keycodes are treated very differently. In console, key stroke signals are translated to a Linux keycode map, which is not used in X at all. In X, these key strokes are read as-is in the form of keycode - which is not the Linux keycode map - and translated to keysyms. So whatever showkey outputs has nothing to do with X. That's where I got it wrong. – Tankman六四 Aug 01 '17 at 06:54