Keyboard mappings - neutrinolabs/xrdp GitHub Wiki

Terminology

Term Meaning
Scancode Value representing a physical key received from the RDP client. See [MS-RDPBCGR]. Essentially a 9 bit value.
Keycode Value used by X11 to represent a physical key. This has essentially the same semantics as an RDP scancode. In the range 8-255
KeySym Encoding of a symbol engraved into a key (e.g. XK_percent for a percent sign
Keyboard mapping table A file in /etc/xrdp which maps keycodes to KeySyms and Unicode characters

Lookup process

The current process, ignoring modifiers, works as follows:-

  1. An RDP scancode is received from the client.
  2. This passes through an xrdp-specific lookup table to generate an keycode.
  3. The keycode is further processed as follows:-
    1. [Login screen] The keycode is looked up in the keyboard mapping table to get a character for the keycode
    2. [VNC backend] The keycode is looked up in the keyboard mapping table to get a KeySym. This is used to inject an X Event into Xvnc.
    3. [Xorg backend] The RDP scancode is passed to xorgxrdp which performs its own translation. The keyboard mapping table is not used.

3c will be considered in later versions of this document.

Keycode

The translation from scancode to keycode seems a bit pointless based on the above description. Why go through an intermediate value? The answer is that somehow we need to produce the keyboard mapping tables. Each keyboard mapping table is produced by running a program called genkeymap. This uses the Xlib XLookupString() call to convert all 247 keycodes into KeySyms and characters. Before the program is run, the setxkbmap program is used to set a particular keyboard model and layout.

This process works fine provided the X11 keycodes used by the X server match the table embedded into xrdp. However, there is no official standard in this area.

When xrdp was created, the predominant X server used was RealVNC. At the time that used its own particular mapping. Since then, a lot has changed:-

  1. Linux (and FreeBSD) have standardised on keycodes produced by the evdev driver.
  2. The predominant VNC server is now RealVNC, which also uses evdev keycodes.

Keycode values (xrdp v0.10.x and earlier)

The following table maps scan codes to keycodes for xrdp v0.10.x and earlier. The keycodes exactly correspond to the values listed in keyboard ini files:

Scancode Keycode Scancode Keycode Scancode Keycode Scancode Keycode
01 9 25 45 49 81 70 120
02 10 26 46 4A 82 71 121
03 11 27 47 4B 83 72 122
04 12 28 48 4C 84 73 123
05 13 29 49 4D 85 74 124
06 14 2A 50 4E 86 75 125
07 15 2B 51 4F 87 76 126
08 16 2C 52 50 88 77 127
09 17 2D 53 51 89 78 128
0A 18 2E 54 52 90 79 129
0B 19 2F 55 53 91 7A 130
0C 20 30 56 54 92 7B 131
0D 21 31 57 55 93 7C 132
0E 22 32 58 56 94 7D 133
0F 23 33 59 57 95 7E 134
10 24 34 60 58 96 7F 135
11 25 35 61 59 97 E0_1C 108
12 26 36 62 5A 98 E0_1D 109
13 27 37 63 5E 102 E0_35 112
14 28 38 64 5F 103 E0_37 111
15 29 39 65 60 104 E0_38 113
16 30 3A 66 61 105 E0_47 97
17 31 3B 67 62 106 E0_48 98
18 32 3C 68 63 107 E0_49 99
19 33 3D 69 64 108 E0_4B 100
1A 34 3E 70 65 109 E0_4D 102
1B 35 3F 71 66 110 E0_4F 103
1C 36 40 72 67 111 E0_50 104
1D 37 41 73 68 112 E0_51 105
1E 38 42 74 69 113 E0_52 106
1F 39 43 75 6A 114 E0_53 107
20 40 44 76 6B 115 E0_5B 115
21 41 45 77 6C 116 E0_5C 116
22 42 46 78 6D 117 E0_5D 117
23 43 47 79 6E 118
24 44 48 80 6F 119

Keycode values (xrdp v0.11.x)

X11 keycodes now used by xrdp are normally the evdev ones, but base can also be selected if required.