Solved 'kbdmap' and keyboard mapping files

Hi all, I have a question about keyboard mapping. Once, I modified the content of the file /usr/share/syscons/keymaps/it.iso.kbd to map some fKeyN onto keys like Ctrl-Insert, Shift-Insert, etc.. I lost that modified keyboard map file, however it worked only for program specifically written to trap specific fkeyN and map it on desired key, for example Midnight Commander will never interpret them as desired key.

I read kbdmap(5), I sent an e-mail to the author of the file it.iso.kbd with no response. Anyone know how to map those special keys ( Modifier-SpecialKey)?

P.S. for both syscons (sc) and vt if there are some differences. I see not much differences, only the ASCII/UNICODE encoding for printable chars.
 
You should copy the kbd file to /etc/keymap and change keymap="/etc/keymap" in rc.conf so you won't loose your changes during an upgrade. The other thing you need to do is use kbdcontrol program with the -f option to assign escape codes to the functions keys so that programs like Midnight Commander will recognize them.

Here's my /etc/keymap file:

Code:
#  alt
# scan  cntrl  alt  alt  cntrl lock
# code  base  shift  cntrl  shift  alt  shift  cntrl  shift state
# ------------------------------------------------------------------
  000  nop  nop  nop  nop  nop  nop  nop  nop  O
  001  esc  esc  esc  esc  esc  esc  debug  esc  O
  002  '1'  '!'  nop  nop  '1'  '!'  nop  nop  O
  003  '2'  '@'  nul  nul  '2'  '@'  nul  nul  O
  004  '3'  '#'  nop  nop  '3'  '#'  nop  nop  O
  005  '4'  '$'  nop  nop  '4'  '$'  nop  nop  O
  006  '5'  '%'  nop  nop  '5'  '%'  nop  nop  O
  007  '6'  '^'  rs  rs  '6'  '^'  rs  rs  O
  008  '7'  '&'  nop  nop  '7'  '&'  nop  nop  O
  009  '8'  '*'  nop  nop  '8'  '*'  nop  nop  O
  010  '9'  '('  nop  nop  '9'  '('  nop  nop  O
  011  '0'  ')'  nop  nop  '0'  ')'  nop  nop  O
  012  '-'  '_'  us  us  '-'  '_'  us  us  O
  013  '='  '+'  nop  nop  '='  '+'  nop  nop  O
  014  bs  bs  del  del  bs  bs  del  del  O
  015  ht  btab  nop  nop  ht  btab  nop  nop  O
  016  'q'  'Q'  dc1  dc1  'q'  'Q'  dc1  dc1  C
  017  'w'  'W'  etb  etb  'w'  'W'  etb  etb  C
  018  'e'  'E'  enq  enq  'e'  'E'  enq  enq  C
  019  'r'  'R'  dc2  dc2  'r'  'R'  dc2  dc2  C
  020  't'  'T'  dc4  dc4  't'  'T'  dc4  dc4  C
  021  'y'  'Y'  em  em  'y'  'Y'  em  em  C
  022  'u'  'U'  nak  nak  'u'  'U'  nak  nak  C
  023  'i'  'I'  ht  ht  'i'  'I'  ht  ht  C
  024  'o'  'O'  si  si  'o'  'O'  si  si  C
  025  'p'  'P'  dle  dle  'p'  'P'  dle  dle  C
  026  '['  '{'  esc  esc  '['  '{'  esc  esc  O
  027  ']'  '}'  gs  gs  ']'  '}'  gs  gs  O
  028  cr  cr  nl  nl  fkey94 cr  nl  nl  O
  029  lctrl  lctrl  lctrl  lctrl  lctrl  lctrl  lctrl  lctrl  O
  030  'a'  'A'  soh  soh  'a'  'A'  soh  soh  C
  031  's'  'S'  dc3  dc3  's'  'S'  dc3  dc3  C
  032  'd'  'D'  eot  eot  'd'  'D'  eot  eot  C
  033  'f'  'F'  ack  ack  'f'  'F'  ack  ack  C
  034  'g'  'G'  bel  bel  'g'  'G'  bel  bel  C
  035  'h'  'H'  bs  bs  'h'  'H'  bs  bs  C
  036  'j'  'J'  nl  nl  'j'  'J'  nl  nl  C
  037  'k'  'K'  vt  vt  'k'  'K'  vt  vt  C
  038  'l'  'L'  ff  ff  'l'  'L'  ff  ff  C
  039  ';'  ':'  nop  nop  ';'  ':'  nop  nop  O
  040  '''  '"'  nop  nop  '''  '"'  nop  nop  O
  041  '`'  '~'  nop  nop  '`'  '~'  nop  nop  O
  042  lshift lshift lshift lshift lshift lshift lshift lshift  O
  043  '\'  '|'  fs  fs  '\'  '|'  fs  fs  O
  044  'z'  'Z'  sub  sub  'z'  'Z'  sub  sub  C
  045  'x'  'X'  can  can  'x'  'X'  can  can  C
  046  'c'  'C'  etx  etx  'c'  'C'  etx  etx  C
  047  'v'  'V'  syn  syn  'v'  'V'  syn  syn  C
  048  'b'  'B'  stx  stx  'b'  'B'  stx  stx  C
  049  'n'  'N'  so  so  'n'  'N'  so  so  C
  050  'm'  'M'  cr  cr  'm'  'M'  cr  cr  C
  051  ','  '<'  nop  nop  ','  '<'  nop  nop  O
  052  '.'  '>'  nop  nop  '.'  '>'  nop  nop  O
  053  '/'  '?'  nop  nop  fkey95 fkey96 nop  nop  O
  054  rshift rshift rshift rshift rshift rshift rshift rshift  O
  055  '*'  '*'  '*'  '*'  '*'  '*'  '*'  '*'  O
  056  lalt  lalt  lalt  lalt  lalt  lalt  lalt  lalt  O
  057  ' '  ' '  nul  ' '  ' '  ' '  susp  ' '  O
  058  clock  clock  clock  clock  clock  clock  clock  clock  O
  059  fkey01 fkey13 fkey25 fkey37 scr01  scr11  scr01  scr11  O
  060  fkey02 fkey14 fkey26 fkey38 scr02  scr12  scr02  scr12  O
  061  fkey03 fkey15 fkey27 fkey39 scr03  scr13  scr03  scr13  O
  062  fkey04 fkey16 fkey28 fkey40 scr04  scr14  scr04  scr14  O
  063  fkey05 fkey17 fkey29 fkey41 scr05  scr15  scr05  scr15  O
  064  fkey06 fkey18 fkey30 fkey42 scr06  scr16  scr06  scr16  O
  065  fkey07 fkey19 fkey31 fkey43 scr07  scr07  scr07  scr07  O
  066  fkey08 fkey20 fkey32 fkey44 scr08  scr08  scr08  scr08  O
  067  fkey09 fkey21 fkey33 fkey45 scr09  scr09  scr09  scr09  O
  068  fkey10 fkey22 fkey34 fkey46 scr10  scr10  scr10  scr10  O
  069  nlock  nlock  nlock  nlock  nlock  nlock  nlock  nlock  O
  070  slock  slock  slock  slock  slock  slock  slock  slock  O
  071  fkey49 fkey65 fkey75 fkey65 '7'  fkey65 '7'  '7'  N
  072  fkey50 fkey66 fkey76 fkey66 '8'  fkey66 '8'  '8'  N
  073  fkey51 fkey67 fkey77 fkey67 '9'  fkey67 '9'  '9'  N
  074  fkey52 '-'  '-'  fkey52 '-'  '-'  '-'  '-'  N
  075  fkey53 fkey68 fkey78 fkey68 '4'  fkey68 '4'  '4'  N
  076  fkey54 fkey54 fkey54 fkey54 '5'  '5'  '5'  '5'  N
  077  fkey55 fkey69 fkey79 fkey69 '6'  fkey69 '6'  '6'  N
  078  fkey56 '+'  '+'  fkey56 '+'  '+'  '+'  '+'  N
  079  fkey57 fkey70 fkey80 fkey70 '1'  fkey70 '1'  '1'  N
  080  fkey58 fkey71 fkey81 fkey71 '2'  fkey71 '2'  '2'  N
  081  fkey59 fkey72 fkey82 fkey72 '3'  fkey72 '3'  '3'  N
  082  fkey60 fkey73 fkey83 fkey73 '0'  fkey73 '0'  '0'  N
  083  fkey61 fkey74 fkey84 fkey74 '.'  fkey74 boot  '.'  N
  084  nop  nop  nop  nop  nop  nop  nop  nop  O
  085  nop  nop  nop  nop  nop  nop  nop  nop  O
  086  nop  nop  nop  nop  nop  nop  nop  nop  O
  087  fkey11 fkey23 fkey35 fkey47 scr11  scr11  scr11  scr11  O
  088  fkey12 fkey24 fkey36 fkey48 scr12  scr12  scr12  scr12  O
  089  cr  cr  nl  nl  cr  cr  nl  nl  O
  090  rctrl  rctrl  rctrl  rctrl  rctrl  rctrl  rctrl  rctrl  O
  091  '/'  '/'  '/'  '/'  '/'  '/'  '/'  '/'  N
  092  nscr  pscr  debug  debug  nop  nop  nop  nop  O
  093  ralt  ralt  ralt  ralt  ralt  ralt  ralt  ralt  O
  094  fkey49 fkey65 fkey75 fkey65 fkey49 fkey49 fkey49 fkey49  O
  095  fkey50 fkey66 fkey76 fkey66 fkey50 fkey50 fkey50 fkey50  O
  096  fkey51 fkey67 fkey77 fkey67 fkey51 fkey51 fkey51 fkey51  O
  097  fkey53 fkey68 fkey78 fkey68 fkey53 fkey53 fkey53 fkey53  O
  098  fkey55 fkey69 fkey79 fkey69 fkey55 fkey55 fkey55 fkey55  O
  099  fkey57 fkey70 fkey80 fkey70 fkey57 fkey57 fkey57 fkey57  O
  100  fkey58 fkey71 fkey81 fkey71 fkey58 fkey58 fkey58 fkey58  O
  101  fkey59 fkey72 fkey82 fkey72 fkey59 fkey59 fkey59 fkey59  O
  102  fkey60 fkey73 fkey83 fkey73 fkey60 fkey60 fkey60 fkey60  O
  103  fkey61 fkey74 fkey84 fkey74 fkey61 fkey61 boot  fkey61  O
  104  slock  saver  slock  saver  susp  nop  susp  nop  O
  105  fkey62 fkey62 fkey62 fkey62 fkey62 fkey62 fkey62 fkey62  O
  106  fkey63 fkey63 fkey63 fkey63 fkey63 fkey63 fkey63 fkey63  O
  107  fkey64 fkey64 fkey64 fkey64 fkey64 fkey64 fkey64 fkey64  O
  108  nop  nop  nop  nop  nop  nop  nop  nop  O

  dgra  '`'  ( 'a' 224 ) ( 'A' 192 ) ( 'e' 232 ) ( 'E' 200 )
  ( 'i' 236 ) ( 'I' 204 ) ( 'o' 242 ) ( 'O' 210 )
  ( 'u' 249 ) ( 'U' 217 )
  dacu  180  ( 'a' 225 ) ( 'A' 193 ) ( 'e' 233 ) ( 'E' 201 )
  ( 'i' 237 ) ( 'I' 205 ) ( 'o' 243 ) ( 'O' 211 )
  ( 'u' 250 ) ( 'U' 218 ) ( 'y' 253 ) ( 'Y' 221 )
  dcir  '^'  ( 'a' 226 ) ( 'A' 194 ) ( 'e' 234 ) ( 'E' 202 )
  ( 'i' 238 ) ( 'I' 206 ) ( 'o' 244 ) ( 'O' 212 )
  ( 'u' 251 ) ( 'U' 219 )
  dtil  '~'  ( 'a' 227 ) ( 'A' 195 ) ( 'n' 241 ) ( 'N' 209 )
  ( 'o' 245 ) ( 'O' 213 )
  duml  168  ( 'a' 228 ) ( 'A' 196 ) ( 'e' 235 ) ( 'E' 203 )
  ( 'i' 239 ) ( 'I' 207 ) ( 'o' 246 ) ( 'O' 214 )
  ( 'u' 252 ) ( 'U' 220 ) ( 'y' 255 )
  drin  176  ( 'a' 229 ) ( 'A' 197 )
  dced  184  ( 'c' 231 ) ( 'C' 199 )

And here are my function key escapes:

Code:
/* 01-04 */   "\033[M"  , "\033[N"  , "\033[O"  , "\033[P"  ,
/* 05-08 */   "\033[Q"  , "\033[R"  , "\033[S"  , "\033[T"  ,
/* 09-12 */   "\033[U"  , "\033[V"  , "\033[W"  , "\033[X"  ,
/* 13-16 */   "\033[Y"  , "\033[Z"  , "\033[a"  , "\033[b"  ,
/* 17-20 */   "\033[c"  , "\033[d"  , "\033[e"  , "\033[f"  ,
/* 21-24 */   "\033[g"  , "\033[h"  , "\033[i"  , "\033[j"  ,
/* 25-28 */   "\033[k"  , "\033[l"  , "\033[m"  , "\033[n"  ,
/* 29-32 */   "\033[o"  , "\033[p"  , "\033[q"  , "\033[r"  ,
/* 33-36 */   "\033[s"  , "\033[t"  , "\033[u"  , "\033[v"  ,
/* 37-40 */   "\033[w"  , "\033[x"  , "\033[y"  , "\033[z"  ,
/* 41-44 */   "\033[@"  , "\033[["  , "\033[\\"  , "\033[]"  ,
/* 45-48 */   "\033[^"  , "\033[_"  , "\033[`"  , "\033[{"  ,
/* 49-52 */   "\033[H"  , "\033[A"  , "\033[I"  , "-"  ,
/* 53-56 */   "\033[D"  , "\033[E"  , "\033[C"  , "+"  ,
/* 57-60 */   "\033[F"  , "\033[B"  , "\033[G"  , "\033[L"  ,
/* 61-64 */   "\177"  , "\033[J"  , "\033[~"  , "\033[}"  ,
/* 65-68 */   "\033[1;2H", "\033[1;2A", "\033[5;2~", "\033[1;2D",
/* 69-72 */   "\033[1;2C", "\033[1;2F", "\033[1;2B", "\033[6;2~",
/* 73-76 */   "\033[2;2~", "\033[3;2~", "\033[1;5H", "\033[1;5A",
/* 77-80 */   "\033[5;5~", "\033[1;5D", "\033[1;5C", "\033[1;5F",
/* 81-84 */   "\033[1;5B", "\033[6;5~", "\033[2;5~", "\033[3;5~",
/* 85-88 */   ""  , ""  , ""  , ""  ,
/* 89-92 */   ""  , ""  , ""  , ""  ,
/* 93-96 */   ""  , "\033\n"  , "\033/"  , "\033?"  ,

Unfortunately kbdcontrol doesn't load function key definitions from a file so you have to do them one at a time, just remove the quotes around each sequence. I just modified my kbdcontrol to make them the -F defaults.

The above will give you pretty much complete functionality in Midnight Commander except when numlock is on. I modified my kernel to make numlock act as alt instead of shift. So either don't use numlock, modify the keymap to put the numlocked keys back to normal, or use my patch:

Code:
--- kbd.c   (revision 305452)
+++ kbd.c   (working copy)
@@ -1247,11 +1247,17 @@
     i += ALTGR_OFFSET;
   key = &kbd->kb_keymap->key;
   i = ((state & SHIFTS) ? 1 : 0)
-    | ((state & CTLS) ? 2 : 0)
-    | ((state & ALTS) ? 4 : 0);
-   if (((key->flgs & FLAG_LOCK_C) && (state & CLKED))
-     || ((key->flgs & FLAG_LOCK_N) && (state & NLKED)) )
+    | ((state & CTLS) ? 2 : 0);
+   if ((key->flgs & FLAG_LOCK_C) && (state & CLKED))
     i ^= 1;
+   if ((key->flgs & FLAG_LOCK_N) &&
+    !( ((key->spcl & (0x80 >> i)) && (key->map == RBT)) ||
+    ((key->spcl & (0x80 >> (i | 4))) && (key->map[i | 4] == RBT)) )) {
+  
+     i |= (state & NLKED) ? 4 : 0;
+   } else {
+     i |= (state & ALTS) ? 4 : 0;
+   }
   if (up) {   /* break: key released */
     action = kbd->kb_lastact[keycode];
 
I just switched my console from sc to vt this morning. Found out that the custom function key sequences were not working. Tuns out that vt is missing the code for that. So I whipped up a quick patch to fix it.

Found out some interesting things. Both the sc and vt console hard code the unshifted F1-F12, Arrow, Ins, Del, Home, End, PgUp and PgDown keys. Sc does this before asking the keyboard driver for the custom functions def for that key. I made vt do the same thing. Incidentally the kbdcontrol -F definitions for those keys are wrong but I guess nobody noticed as the terminal overrode them.

Plus the vt color palette is horrid. The blue is way to bright and makes Midnight Commander look like crap. I changed it to the standard VGA colors in my patch.

So here is the full path for those that want all there keys working in Midnight Commander:

Code:
Index: sys/dev/kbd/kbd.c
===================================================================
--- sys/dev/kbd/kbd.c   (revision 305452)
+++ sys/dev/kbd/kbd.c   (working copy)
@@ -1247,11 +1247,17 @@
     i += ALTGR_OFFSET;
   key = &kbd->kb_keymap->key[i];
   i = ((state & SHIFTS) ? 1 : 0)
-    | ((state & CTLS) ? 2 : 0)
-    | ((state & ALTS) ? 4 : 0);
-   if (((key->flgs & FLAG_LOCK_C) && (state & CLKED))
-     || ((key->flgs & FLAG_LOCK_N) && (state & NLKED)) )
+    | ((state & CTLS) ? 2 : 0);
+   if ((key->flgs & FLAG_LOCK_C) && (state & CLKED))
     i ^= 1;
+   if ((key->flgs & FLAG_LOCK_N) &&
+    !( ((key->spcl & (0x80 >> i)) && (key->map[i] == RBT)) ||
+    ((key->spcl & (0x80 >> (i | 4))) && (key->map[i | 4] == RBT)) )) {
+   
+     i |= (state & NLKED) ? 4 : 0;
+   } else {
+     i |= (state & ALTS) ? 4 : 0;
+   }
   if (up) {   /* break: key released */
     action = kbd->kb_lastact[keycode];
Index: sys/dev/vt/colors/vt_termcolors.c
===================================================================
--- sys/dev/vt/colors/vt_termcolors.c   (revision 305452)
+++ sys/dev/vt/colors/vt_termcolors.c   (working copy)
@@ -40,21 +40,21 @@
   unsigned char b;   /* Blue percentage value. */
 } color_def[16] = {
   {0,   0,   0},   /* black */
-   {50,   0,   0},   /* dark red */
-   {0,   50,   0},   /* dark green */
-   {77,   63,   0},   /* dark yellow */
-   {20,   40,   64},   /* dark blue */
-   {50,   0,   50},   /* dark magenta */
-   {0,   50,   50},   /* dark cyan */
-   {75,   75,   75},   /* light gray */
+   {67,   0,   0},   /* dark red */
+   {0,   67,   0},   /* dark green */
+   {67,   67,   0},   /* dark yellow */
+   {0,   0,   67},   /* dark blue */
+   {67,   0,   67},   /* dark magenta */
+   {0,   67,   67},   /* dark cyan */
+   {67,   67,   67},   /* light gray */
-   {18,   20,   21},   /* dark gray */
-   {100,   0,   0},   /* light red */
-   {0,   100,   0},   /* light green */
-   {100,   100,   0},   /* light yellow */
-   {45,   62,   81},   /* light blue */
-   {100,   0,   100},   /* light magenta */
-   {0,   100,   100},   /* light cyan */
+   {33,   33,   33},   /* dark gray */
+   {100,   33,   33},   /* light red */
+   {33,   100,   33},   /* light green */
+   {100,   100,   33},   /* light yellow */
+   {33,   33,   100},   /* light blue */
+   {100,   33,   100},   /* light magenta */
+   {33,   100,   100},   /* light cyan */
   {100,   100,   100},   /* white */
 };
Index: sys/dev/vt/vt_core.c
===================================================================
--- sys/dev/vt/vt_core.c   (revision 305452)
+++ sys/dev/vt/vt_core.c   (working copy)
@@ -773,6 +773,9 @@
 static int
 vt_processkey(keyboard_t *kbd, struct vt_device *vd, int c)
 {
+   size_t len;
+   const u_char *cp;
+
   struct vt_window *vw = vd->vd_curwindow;
   random_harvest_queue(&c, sizeof(c), 1, RANDOM_KEYBOARD);
@@ -887,6 +890,13 @@
     case FKEY | F(61): /* Delete key. */
       terminal_input_special(vw->vw_terminal, TKEY_DELETE);
       break;
+     default:
+       if (KEYFLAGS(c) == FKEY) {
+         cp = kbdd_get_fkeystr(kbd, KEYCHAR(c), &len);
+         if (cp != NULL) {
+           terminal_input_raw_string(vw->vw_terminal, cp, len);
+         }
+       }
     }
   } else if (KEYFLAGS(c) == 0) {
     /* Don't do UTF-8 conversion when doing raw mode. */
Index: sys/kern/subr_terminal.c
===================================================================
--- sys/kern/subr_terminal.c   (revision 305452)
+++ sys/kern/subr_terminal.c   (working copy)
@@ -317,6 +317,21 @@
 }
 void
+terminal_input_raw_string(struct terminal *tm, const u_char *cp, size_t len)
+{
+   struct tty *tp;
+
+   tp = tm->tm_tty;
+   if (tp == NULL)
+     return;
+
+   tty_lock(tp);
+   ttydisc_rint_simple(tp, cp, len);
+   ttydisc_rint_done(tp);
+   tty_unlock(tp);
+}
+
+void
 terminal_input_special(struct terminal *tm, unsigned int k)
 {
   struct tty *tp;
Index: sys/sys/terminal.h
===================================================================
--- sys/sys/terminal.h   (revision 305452)
+++ sys/sys/terminal.h   (working copy)
@@ -214,6 +214,7 @@
 void   terminal_mute(struct terminal *tm, int yes);
 void   terminal_input_char(struct terminal *tm, term_char_t c);
 void   terminal_input_raw(struct terminal *tm, char c);
+void   terminal_input_raw_string(struct terminal *tm, const u_char *cp, size_t len);
 void   terminal_input_special(struct terminal *tm, unsigned int k);
 void   termcn_cnregister(struct terminal *tm);
Index: usr.sbin/kbdcontrol/kbdcontrol.c
===================================================================
--- usr.sbin/kbdcontrol/kbdcontrol.c   (revision 305452)
+++ usr.sbin/kbdcontrol/kbdcontrol.c   (working copy)
@@ -79,30 +79,30 @@
   };
 static const char fkey_table[96][MAXFK] = {
-/* 01-04 */   "\033[M", "\033[N", "\033[O", "\033[P",
-/* 05-08 */   "\033[Q", "\033[R", "\033[S", "\033[T",
-/* 09-12 */   "\033[U", "\033[V", "\033[W", "\033[X",
-/* 13-16 */   "\033[Y", "\033[Z", "\033[a", "\033[b",
-/* 17-20 */   "\033[c", "\033[d", "\033[e", "\033[f",
-/* 21-24 */   "\033[g", "\033[h", "\033[i", "\033[j",
-/* 25-28 */   "\033[k", "\033[l", "\033[m", "\033[n",
-/* 29-32 */   "\033[o", "\033[p", "\033[q", "\033[r",
-/* 33-36 */   "\033[s", "\033[t", "\033[u", "\033[v",
-/* 37-40 */   "\033[w", "\033[x", "\033[y", "\033[z",
-/* 41-44 */   "\033[@", "\033[[", "\033[\\","\033[]",
-/* 45-48 */  "\033[^", "\033[_", "\033[`", "\033[{",
-/* 49-52 */   "\033[H", "\033[A", "\033[I", "-"  ,
-/* 53-56 */   "\033[D", "\033[E", "\033[C", "+"  ,
-/* 57-60 */   "\033[F", "\033[B", "\033[G", "\033[L",
-/* 61-64 */  "\177",  "\033[J", "\033[~", "\033[}",
-/* 65-68 */   ""  , ""  , ""  , ""  ,
-/* 69-72 */   ""  , ""  , ""  , ""  ,
-/* 73-76 */   ""  , ""  , ""  , ""  ,
-/* 77-80 */   ""  , ""  , ""  , ""  ,
-/* 81-84 */   ""  , ""  , ""  , ""  ,
-/* 85-88 */   ""  , ""  , ""  , ""  ,
-/* 89-92 */   ""  , ""  , ""  , ""  ,
-/* 93-96 */   ""  , ""  , ""  , ""  ,
+/* 01-04 */   "\033OP"  , "\033OQ"  , "\033OR"  , "\033OS"  ,
+/* 05-08 */   "\033[15~" , "\033[17~" , "\033[18~" , "\033[19~" ,
+/* 09-12 */   "\033[20~" , "\033[21~" , "\033[23~" , "\033[24~" ,
+/* 13-16 */   "\033[Y"  , "\033[Z"  , "\033[a"  , "\033[b"  ,
+/* 17-20 */   "\033[c"  , "\033[d"  , "\033[e"  , "\033[f"  ,
+/* 21-24 */   "\033[g"  , "\033[h"  , "\033[i"  , "\033[j"  ,
+/* 25-28 */   "\033[k"  , "\033[l"  , "\033[m"  , "\033[n"  ,
+/* 29-32 */   "\033[o"  , "\033[p"  , "\033[q"  , "\033[r"  ,
+/* 33-36 */   "\033[s"  , "\033[t"  , "\033[u"  , "\033[v"  ,
+/* 37-40 */   "\033[w"  , "\033[x"  , "\033[y"  , "\033[z"  ,
+/* 41-44 */   "\033[@"  , "\033[["  , "\033[\\"  , "\033[]"  ,
+/* 45-48 */   "\033[^"  , "\033[_"  , "\033[`"  , "\033[{"  ,
+/* 49-52 */   "\033[H"  , "\033[A"  , "\033[5~"  , "-"  ,
+/* 53-56 */   "\033[D"  , "\033[E"  , "\033[C"  , "+"  ,
+/* 57-60 */   "\033[F"  , "\033[B"  , "\033[6~"  , "\033[2~"  ,
+/* 61-64 */   "\0333~"  , "\033[J"  , "\033[~"  , "\033[}"  ,
+/* 65-68 */   "\033[1;2H", "\033[1;2A", "\033[5;2~", "\033[1;2D",
+/* 69-72 */   "\033[1;2C", "\033[1;2F", "\033[1;2B", "\033[6;2~",
+/* 73-76 */   "\033[2;2~", "\033[3;2~", "\033[1;5H", "\033[1;5A",
+/* 77-80 */   "\033[5;5~", "\033[1;5D", "\033[1;5C", "\033[1;5F",
+/* 81-84 */   "\033[1;5B", "\033[6;5~", "\033[2;5~", "\033[3;5~",
+/* 85-88 */   ""  , ""  , ""  , ""  ,
+/* 89-92 */   ""  , ""  , ""  , ""  ,
+/* 93-96 */   ""  , "\033\n"  , "\033/"  , "\033?"  ,
   };
 static const int delays[]  = {250, 500, 750, 1000};
[/i][/i]
 
wow, many many thanks Avernar, I will read your posts with more attention and try to do what I'm able to do. In the past I 'moved' the fkeyNN (starting after the last shift+Fn), i.e. to have a key under Ctrl+INS, take a free or unused fkeyNN and move it at the Ctrl+INS coordinate.
Actually I have an headless server, I work on it remotely only (PuTTY), sometimes happens (in 'mc') that the Entrer key on the numeric keypad, sometimes works and some other not, i.e. open 'mc', edit a file, Enter on numpad do nothing. Execute some other tasks, open 'mc', edit a file, pressing Enter on numpad it works.
I do not like to customize OS in the core (system, kernel, and related configuration files) unless it's necessary and the modifications are improvements. Thanks again for your help, I will report back what I understood.
Last thing. I use vt console, but unless I log-on directly on the server, it make no differences, remote access is always an UTF-8 xterm. I guess there are some differences from virtual consoles (ttyvN) and remote consoles (ptsN). I will try.[/cmd][/cmd]
 
The script below is an attempt to get a key (non-blocking) and map it like 'curses' do (in another system are called vitual keys). It's not complete, stopped after I realized I'm not able to map some keys, they are not keys (like Ctrl-INS) unless defined in the .kbd file.

Warning Replace any '{{ESC}}' with the real escape character ('\x1B').

Code:
echo "-------------------------------------------------------"
echo "Non-blocking input test (press 'Q' or 'q' to terminate)"
echo "-------------------------------------------------------"

# Show current TTY settings
#echo -e "\e[1;37mstty\e[0m"
#stty -a

# Backup current TTY settings and set `raw` mode
sTTYBkup=$( stty -g )
stty raw ixon ixany opost iexten cs8 time 0 min 0

# Show current TTY settings
#echo -e "\e[1;37mstty\e[0m"
##stty -a

# Waiting for keys (exit with 'Q' or 'q' key)
sKey=""
sChar=""
while :
do
    char=$( dd bs=1 count=1 2> /dev/null; )
    if [ "$char" = "{{ESC}}" ]; then
        sKey="$char"
        sChar="ESC"
    elif [ -n "$char" ]; then
        sKey="${sKey}${char}"
        sChar="${sChar}${char}"
    else
        # Fine della sequenza, verifico se il carattere è speciale e lo mappo
        if [ -n "$sKey" ]; then
            # Se è stato premuto 'Q' o 'q' esco. Ho utilizzato il carattere `.` prima e dopo i
            # nomi perchè la `if` generava errori
            if [ ".$sChar." = ".q." -o ".$sChar." = ".Q." ]; then
                break
            fi

            #
            iKey=$( printf "%d" "'$sKey" )
            if [ "$iKey" -lt 32 ]; then
                case "$iKey" in
                    1) sChar="Ctrl-A" ;;
                    2) sChar="Ctrl-B" ;;
                    3) sChar="Ctrl-C" ;;
                    4) sChar="Ctrl-D" ;;
                    5) sChar="Ctrl-E" ;;
                    6) sChar="Ctrl-F" ;;
                    7) sChar="Ctrl-G" ;;
                    8) sChar="BackSpace" ;;
                    9) sChar="Tab" ;;
                    10) sChar="Ctrl-J" ;;
                    11) sChar="Ctrl-K" ;;
                    12) sChar="Ctrl-L" ;;
                    13) sChar="Enter" ;;
                    14) sChar="Ctrl-N" ;;
                    15) sChar="Ctrl-O" ;;
                    16) sChar="Ctrl-P" ;;
                    17) sChar="Ctrl-Q" ;;
                    18) sChar="Ctrl-R" ;;
                    19) sChar="Ctrl-S" ;;
                    20) sChar="Ctrl-T" ;;
                    21) sChar="Ctrl-U" ;;
                    22) sChar="Ctrl-V" ;;
                    23) sChar="Ctrl-W" ;;
                    24) sChar="Ctrl-X" ;;
                    25) sChar="Ctrl-Y" ;;
                    26) sChar="Ctrl-Z" ;;
                    # Tasto Esc
                    27)
                        case "$sKey" in
                            # Tasto Esc
                            "{{ESC}}") sChar="Esc" ;;
                            # Tasti funzione
                            "{{ESC}}OP") sChar="F1" ;;
                            "{{ESC}}OQ") sChar="F2" ;;
                            "{{ESC}}OR") sChar="F3" ;;
                            "{{ESC}}OS") sChar="F4" ;;
                            "{{ESC}}[15~") sChar="F5" ;;
                            "{{ESC}}[17~") sChar="F6" ;;
                            "{{ESC}}[18~") sChar="F7" ;;
                            "{{ESC}}[19~") sChar="F8" ;;
                            "{{ESC}}[20~") sChar="F9" ;;
                            "{{ESC}}[21~") sChar="F10" ;;
                            "{{ESC}}[23~") sChar="Shift-F1" ;;
                            "{{ESC}}[24~") sChar="Shift-F2" ;;
                            "{{ESC}}[25~") sChar="Shift-F3" ;;
                            "{{ESC}}[26~") sChar="Shift-F4" ;;
                            "{{ESC}}[28~") sChar="Shift-F5" ;;
                            "{{ESC}}[29~") sChar="Shift-F6" ;;
                            "{{ESC}}[31~") sChar="Shift-F7" ;;
                            "{{ESC}}[32~") sChar="Shift-F8" ;;
                            "{{ESC}}[33~") sChar="Shift-F9" ;;
                            "{{ESC}}[34~") sChar="Shift-F10" ;;
                            "{{ESC}}[1;3P") sChar="Alt-F1" ;;
                            "{{ESC}}[1;3Q") sChar="Alt-F2" ;;
                            "{{ESC}}[1;3R") sChar="Alt-F3" ;;
                            "{{ESC}}[1;3S") sChar="Alt-F4" ;;
                            "{{ESC}}[15;3~") sChar="Alt-F5" ;;
                            "{{ESC}}[17;3~") sChar="Alt-F6" ;;
                            "{{ESC}}[18;3~") sChar="Alt-F7" ;;
                            "{{ESC}}[19;3~") sChar="Alt-F8" ;;
                            "{{ESC}}[20;3~") sChar="Alt-F9" ;;
                            "{{ESC}}[21;3~") sChar="Alt-F10" ;;
                            "{{ESC}}[23;3~") # Questa è mappata anche come Alt-Shift-F1
                                sChar="Alt-F11" ;;
                            "{{ESC}}[24;3~") # Questa è mappata anche come Alt-Shift-F2
                                sChar="Alt-F12" ;;
                           # Tasti cursore
                           "{{ESC}}[A") sChar="Up" ;;
                           "{{ESC}}[B") sChar="Down" ;;
                           "{{ESC}}[C") sChar="Right" ;;
                           "{{ESC}}[D") sChar="Left" ;;
                           "{{ESC}}[1~") sChar="Home" ;;
                           "{{ESC}}[4~") sChar="End" ;;
                           "{{ESC}}[5~") sChar="PageUp" ;;
                           "{{ESC}}[6~") sChar="PageDown" ;;
                           "{{ESC}}[G") sChar="Tn5" ;;
                           "{{ESC}}[2~") sChar="Insert" ;;
                           "{{ESC}}[3~") sChar="Delete" ;;
                           "{{ESC}}[2;3~") sChar="Alt-Insert" ;;
                           "{{ESC}}[3;3~") sChar="Alt-Delete" ;;
                           "{{ESC}}.") sChar="Alt-Delete" ;;
                           # Alt + carattere
                           "{{ESC}}a") sChar="Alt-A" ;;
                           "{{ESC}}b") sChar="Alt-B" ;;
                           "{{ESC}}c") sChar="Alt-C" ;;
                           "{{ESC}}d") sChar="Alt-D" ;;
                           "{{ESC}}e") sChar="Alt-E" ;;
                           "{{ESC}}f") sChar="Alt-F" ;;
                           "{{ESC}}g") sChar="Alt-G" ;;
                           "{{ESC}}h") sChar="Alt-H" ;;
                           "{{ESC}}i") sChar="Alt-I" ;;
                           "{{ESC}}j") sChar="Alt-J" ;;
                           "{{ESC}}k") sChar="Alt-K" ;;
                           "{{ESC}}l") sChar="Alt-L" ;;
                           "{{ESC}}m") sChar="Alt-M" ;;
                           "{{ESC}}n") sChar="Alt-N" ;;
                           "{{ESC}}o") sChar="Alt-O" ;;
                           "{{ESC}}p") sChar="Alt-P" ;;
                           "{{ESC}}q") sChar="Alt-Q" ;;
                           "{{ESC}}r") sChar="Alt-R" ;;
                           "{{ESC}}s") sChar="Alt-S" ;;
                           "{{ESC}}t") sChar="Alt-T" ;;
                           "{{ESC}}u") sChar="Alt-U" ;;
                           "{{ESC}}v") sChar="Alt-V" ;;
                           "{{ESC}}w") sChar="Alt-W" ;;
                           "{{ESC}}x") sChar="Alt-X" ;;
                           "{{ESC}}y") sChar="Alt-Y" ;;
                           "{{ESC}}z") sChar="Alt-Z" ;;
                           "{{ESC}}
") sChar="Alt-Enter" ;;
                           "{{ESC}}\b") sChar="Alt-Backspace" ;;
                           # Alt + Shift +char
                           "{{ESC}}A") sChar="Alt-Shift-A";;
                           "{{ESC}}B") sChar="Alt-Shift-B" ;;
                           "{{ESC}}C") sChar="Alt-Shift-C" ;;
                           "{{ESC}}D") sChar="Alt-Shift-D" ;;
                           "{{ESC}}E") sChar="Alt-Shift-E" ;;
                           "{{ESC}}F") sChar="Alt-Shift-F" ;;
                           "{{ESC}}G") sChar="Alt-Shift-G" ;;
                           "{{ESC}}H") sChar="Alt-Shift-H" ;;
                           "{{ESC}}I") sChar="Alt-Shift-I" ;;
                           "{{ESC}}J") sChar="Alt-Shift-J" ;;
                           "{{ESC}}K") sChar="Alt-Shift-K" ;;
                           "{{ESC}}L") sChar="Alt-Shift-L" ;;
                           "{{ESC}}M") sChar="Alt-Shift-M" ;;
                           "{{ESC}}N") sChar="Alt-Shift-N" ;;
                           "{{ESC}}O") sChar="Alt-Shift-O" ;;
                           "{{ESC}}P") sChar="Alt-Shift-P" ;;
                           "{{ESC}}Q") sChar="Alt-Shift-Q" ;;
                           "{{ESC}}R") sChar="Alt-Shift-R" ;;
                           "{{ESC}}S") sChar="Alt-Shift-S" ;;
                           "{{ESC}}T") sChar="Alt-Shift-T" ;;
                           "{{ESC}}U") sChar="Alt-Shift-U" ;;
                           "{{ESC}}V") sChar="Alt-Shift-V" ;;
                           "{{ESC}}W") sChar="Alt-Shift-W" ;;
                           "{{ESC}}X") sChar="Alt-Shift-X" ;;
                           "{{ESC}}Y") sChar="Alt-Shift-Y" ;;
                           "{{ESC}}Z") sChar="Alt-Shift-Z" ;;
                       esac
                       ;;
                   28) sChar="Ctrl-\\" ;;
                   29) sChar="Ctrl-]" ;;
                   30) sChar="Ctrl-^" ;;
                   31) sChar="Ctrl-_" ;;
               esac
           fi
           # Visualizzo il risultato
           echo "key: '$sChar'"
           bSpecial=false
           sKey=""
           sChar=""
    fi
fi
done

stty $sTTYBkup

Pasting code messed it up, hope it works.

EDIT: Perhaps this is the blocking version.
As a note: I extracted this code from a more large testing script to paste it here. I pasted the code in a new file, set the executable flag with chmod +x file and ran it. It runs without shebang (missing #!/bin/sh at first line). FreeBSD 10.3-RELEASE p7 amd64 (real machine).
 
Ok. I know what to do (more or less). I still not have a full remap of the keyboard map file and still not seen what happen to NumLock but I think it can work as expected remapping only some modifier+key. The new map is for sc (syscons) driver, not vt. I have two FreeBSD installations, both 10.3-RELEASE, one real and the other in VM, with vt driver but not sure if the driver is properly configured, I loaded the two KMS drivers in /boot/loader.conf... as follows

# Extracted drom /boot/loader.conf

# Console 'vt' driver + Intel and AMD 'KMS' drivers ('i915kms', 'radeonkms')
i915kms_load="YES"
radeonkms_load="YES"
#hw.vga.textmode="1"
kern.vty="vt"
kern.vt.fb.default_mode="1024x768"



The command kldstat shows both are loaded


Id Refs Address Size Name
1 40 0xffffffff80200000 17bc718 kernel
2 1 0xffffffff819bd000 4a70 coretemp.ko
3 1 0xffffffff819c2000 12340 tmpfs.ko
4 1 0xffffffff81c19000 56c6 fdescfs.ko
5 1 0xffffffff81c1f000 17539 drm.ko
6 3 0xffffffff81c37000 5232a drm2.ko
7 5 0xffffffff81c8a000 2404 iicbus.ko
8 1 0xffffffff81c8d000 7874d i915kms.ko
9 2 0xffffffff81d06000 1c5e iic.ko
10 2 0xffffffff81d08000 1e2b iicbb.ko
11 1 0xffffffff81d0a000 11777e radeonkms.ko


It works at 640x480. (don't know who or what load the I²C bus drivers, it flashes into my mind bad days).

I say this cos I want to try (when finished) the map for vt driver too. The only thing I need to know (and implicitly it was my original question) is: 'Where to get the keyboard keys right escape sequences?' I read (not in deep) ECMA 048 and several other documents: vt100.net to take one. The best document that say something clear about this argument is XTerm Control Sequences.

In that document at the end (very end) of the section PC-Style Function Keys there's a table that shows how to add modifiers to CSI keys. Is there a unerstandable standard for key mapping? I can try to set for example Shift-Left to something like CSI D ; 2 (the ; 2 is the 'Shift' modifier).

Avernar
For some keys in your mapping I didn't found a match in the above documents, 'How you guessed them? :)'

Then, solved this (when solved), I guess I will have to do the same thing for a shell in PuTTY (termcap/terminfo ?).
 
It was a while ago when I found those escape sequences. I believe I just checked the Midnight Commander source code to see what it looked for for each key. Some keys it could respond to more than one sequence. I can't remember what criteria I used to pick.
 
It was a while ago when I found those escape sequences. I believe I just checked the Midnight Commander source code to see what it looked for for each key.

Looking into Midnight Commander sources was also what come to my mind, I thought there was a standard or at least an unofficial 'habit list'.

Some keys it could respond to more than one sequence. I can't remember what criteria I used to pick.

Yes, some of the sequences you posted use the criteria of the 'modifier suffix', some other are 'unknown' (I didn't found a match).

Many thanks Avernar, your posts are precious anyways.
 
Back
Top