2

This question already has an answer here:

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 
    <AE01> = 10;

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

marked as duplicate by Stefan, cas, Anthon, meuh, Romeo Ninov Jul 31 '17 at 10:50

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

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
  • 1
    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 1 '17 at 6:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.