9.2. X Windows System interface

9.2.1. Keyboard mapping

Wine now needs to know about your keyboard layout. This requirement comes from a need from many apps to have the correct scancodes available, since they read these directly, instead of just taking the characters returned by the X server. This means that Wine now needs to have a mapping from X keys to the scancodes these programs expect.

On startup, Wine will try to recognize the active X layout by seeing if it matches any of the defined tables. If it does, everything is alright. If not, you need to define it.

To do this, open the file dlls/winex11.drv/keyboard.c and take a look at the existing tables.

What you really would need to do, is find out which scancode each key needs to generate. Find it in the main_key_scan table, which looks like this:

static const int main_key_scan[MAIN_LEN] =
/* this is my (102-key) keyboard layout, sorry if it doesn't quite match yours */
0x56 /* the 102nd key (actually to the right of l-shift) */

Next, assign each scancode the characters imprinted on the keycaps. This was done (sort of) for the US 101-key keyboard, which you can find near the top in keyboard.c. It also shows that if there is no 102nd key, you can skip that.

However, for most international 102-key keyboards, we have done it easy for you. The scancode layout for these already pretty much matches the physical layout in the main_key_scan, so all you need to do is to go through all the keys that generate characters on your main keyboard (except spacebar), and stuff those into an appropriate table. The only exception is that the 102nd key, which is usually to the left of the first key of the last line (usually Z), must be placed on a separate line after the last line.

After you have written such a table, you need to add it to the main_key_tab[] layout index table. This will look like this:

static struct {
WORD lang, ansi_codepage, oem_codepage;
const char (*key)[MAIN_LEN][4];
} main_key_tab[]={

After you have added your table, recompile Wine and test that it works. If it fails to detect your table, try running

WINEDEBUG=+key,+keyboard wine > key.log 2>&1

and look in the resulting key.log file to find the error messages it gives for your layout.

Note that the LANG_* and SUBLANG_* definitions are in include/winnls.h, which you might need to know to find out which numbers your language is assigned, and find it in the WINEDEBUG output. The numbers will be (SUBLANG * 0x400 + LANG), so, for example the combination LANG_NORWEGIAN (0x14) and SUBLANG_DEFAULT (0x1) will be (in hex) 14 + 1*400 = 414, so since I'm Norwegian, I could look for 0414 in the WINEDEBUG output to find out why my keyboard won't detect.