Questions about the Linux console keyboard driver / translation tables

Hi there,

I am trying to understand the logic of the Linux keyboard driver, I am not sure if this is the right place to ask, but I don't know where else I could.

Btw. I am talking about an unicode console here.

1.) The Linux kernel (currently) can take 256 translation tables (keymaps), I figured that if I have 8 Mod-Keys and I can press two at the same time, then this makes 256 possible modifications.
E.g. the value of my keycode of the button 'a' is 0x0b61 (small letter a) in table 0 and 0x0b41 (capital letter A) in table 1, so is it true that table 1 is for shift pressed keycodes?
If so, then why is shift (KG_SHIFT in linux/keyboard.h) set to 0, and how do I compute the modifications, meaning how do I know what e.g. index 231 represents?

2.) As seen above, the value for 'a' is actually 0x0b61 instead of 0x0061, if b indicates a type (here KT_LOCK) why isn't it 0xfb61, because I thought that only values above 0xf000 represent typed values, and the values below are simply unicode values.
The values above are read via the KDGKBENT ioctl, are these values read differently then written?
E.g. would I only type 0xfb61 when using the KDSKBENT ioctl?

I hope anyone can help me out a little,
thank you very much in advance,
regards,
Bill

The first thing we need to see what is going on, please post the output of

locale

from the console. This affects what you're talking about in a big way. "unicode" may be one of several things, so we are all on the same code page.

Hm, I am talking about kernel system calls, I didn't think the locale is involved here.
With "unicode" I mean one of the 4 states for the console after

man 4 console_ioctl

which are:

K_RAW
K_XLATE
K_MEDIUMRAW
K_UNICODE

You can set these with the

ioctl KDSKBMODE

Unicode just means that the kernel console driver will handle characters as two bytes long (unsigned short).

The values I am talking about I acquired through the KDGKBENT ioctl, like this:

#include <stdio.h>
#include <stdlib.h>
#include <linux/keyboard.h>
#include <sys/ioctl.h>
#include <sys/kd.h>

int
main(int argc, char **argv) {
  struct kbentry ke;
  
  ke.kb_table = (unsigned char)atoi(argv[1]);
  ke.kb_index = (unsigned char)atoi(argv[2]);
  ioclt(0, KDGKBENT, &ke);
  printf("keycode %u = %04x\n", ke.kb_index, ke.kb_value);
  return 0;
}

If you compile this program and invoke it with the first parameter as one of the above mentioned 256 keymap tables, and the second parameter as your keycode, it will print the corresponding value.
You can use showkey(1) to get a keycode from your keyboard (it doesn't work while in X I assume)

E.g. When I press 'a' during showkey(1) I get the keycode 40, if I then invoke my program like

./a.out 0 40

I get

keycode 40 = 0b61

Where 0061 would be the utf-8 (and ascii) representation of 'a', if I use 1 instead of 0 I get 0b41, where 0041 would be capital letter 'A'

This should all be independent of the locale, it depends on the defined keymap(5)

Now I am wondering what the 0x0b is doing there, it could be the KT_LOCK function (defined in linux/keyboard.h), but then I am wondering why it is not 0xfb, because functions need to be greater than 0xf000, or so I thought.

I hope you are seeing where I am getting at, my in- and output on the console is jut fine, I am only wondering about the internals.

Regarding this, this is the most interesting link I have found so far: (The part I am interested in starts at section: "Key maps in the kernel")
h**p://gunnarwrobel.de/wiki/Linux-and-the-keyboard.html

But for what it's worth, here my locale output:

LANG=de_DE.utf8
LC_CTYPE="de_DE.utf8"
LC_NUMERIC="de_DE.utf8"
LC_TIME="de_DE.utf8"
LC_COLLATE="de_DE.utf8"
LC_MONETARY="de_DE.utf8"
LC_MESSAGES="de_DE.utf8"
LC_PAPER="de_DE.utf8"
LC_NAME="de_DE.utf8"
LC_ADDRESS="de_DE.utf8"
LC_TELEPHONE="de_DE.utf8"
LC_MEASUREMENT="de_DE.utf8"
LC_IDENTIFICATION="de_DE.utf8"
LC_ALL=

regards.