Solved Binding Ctrl+Left/Right to back/forward-word outside X

The usual solution is editing $HOME/.inputrc for bash and $HOME/.cshrc for csh. These are mine:

.inputrc
Code:
"\e[1;5C": forward-word
"\e[1;5D": backward-word

.cshrc
Code:
# $FreeBSD: releng/11.0/share/skel/dot.cshrc 278616 2015-02-12 05:35:00Z cperciva $
#
# .cshrc - csh resource script, read at beginning of execution by each shell
#
# see also csh(1), environ(7).
# more examples available at /usr/share/examples/csh/
#

alias h        history 25
alias j        jobs -l
alias la    ls -aF
alias lf    ls -FA
alias ll    ls -lAF

# These are normally set through /etc/login.conf.  You may override them here
# if wanted.
# set path = (/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin $HOME/bin)
# setenv    BLOCKSIZE    K
# A righteous umask
# umask 22

setenv    EDITOR    vi
setenv    PAGER    more

if ($?prompt) then
    # An interactive shell -- set some stuff up
    set prompt = "%N@%m:%~ %# "
    set promptchars = "%#"

    set filec
    set history = 1000
    set savehist = (1000 merge)
    set autolist = ambiguous
    # Use history to aid expansion
    set autoexpand
    set autorehash
    set mail = (/var/mail/$USER)
    if ( $?tcsh ) then
        bindkey "^W" backward-delete-word
        bindkey -k up history-search-backward
        bindkey -k down history-search-forward
        if ("$TERM" == "cons25") then
           bindkey "^?" delete-char
                else if ("$TERM" == "linux") then
                    bindkey "^[[3~" delete-char
                else if ("$TERM" == "xterm" || "$TERM" == "xterm-clear") then
                    bindkey "^[[3~" delete-char
                    bindkey "^[[5C" forward-word
                    bindkey "^[[1;5C" forward-word
                    bindkey "^[[5D" backward-word
                    bindkey "^[[1;5D" backward-word
                    # bindkey "\303\277" backward-delete-word
                endif

    endif

endif

That works fine if running X, but fails otherwise. Note that only these two specific bindings do not work. For example, the Delete key won't work in csh without a bindkey "^[[3~" delete-char. However, once .cshrc is properly edited, ths issue is fixed regardless of running inside X or not.

However, Ctrl+Left yields the "^[[1;5D" ("\e[1;5D") CSI only in X terminal emulators. In console it's bound to "^[[D" which is the same as pressing the Left arrow alone, with no modifiers. As such, binding "^[[D" itself can't be a solution since it would conflict with "normal" backward-char cursor moving. Likewise, Right/Ctrl+Right present similar issues.

It happened on my GNU Linux as well and I managed to fix it. First, I got the arrows and the letter 'b' keycodes through showkey. So far, cat or even xev could serve the same purpose in FreeBSD.

I apologize for mistaking. cat will do the same as C-v (outputs "^[[D" instead of pressed keycode).

Then I dumped current keymap through dumpkeys -1 and checked the Alt modifier for 'b'. The entry read Meta_b, so I created a custom.kmap file like follows:
Code:
keymaps 0-127
control keycode 100 = Meta_b

Since Meta_b was referring to the letter 'b' key with the alt modifier, that's just like saying Alt+b, or M-b - which happens to be default keybind for backward-word. Done.

I tried to adapt this solution. kbdcontrol -d gave me the keymap just like dumpkeys would. All entries for keycode 100 (Left arrow) are set with "fkey58". I tried changing it to a quoted CSI, other than "^[[D" which I can't remap. I tried both"^[[1;5D" and "^[[5D" as shown in my .cshrc, then finally "^[b" (Alt+b as listed in csh with bindkey). After changing the corresponding entry I reloaded the custom keymap with # kbdcontrol -l custom.kbd, but nothing has changed. Regardless of what was replacing "fkey58", testing with C-v printed the same "^[[D" all the time.

As a last resource I tried # kbdcontrol -f 65 "echo -e \e[5D" and replace fkey58 with fkey65 in Control column of keycode 100. It didn't work. Actually, I later changed it to # kbdcontrol -f 65 "echo TEST". Still, instead of echoing "TEST" on tty, it printed the usual "^[[D".

It seems Ctrl+Left won't change regardless of what I do. Even changing it to a free function key (fkey65) and assigning a simple command such as echo TEST won't work. Still, as far as kbdcontrol(1) goes fkey10 can be set to run telnet. What am I doing wrong here? M-b and M-f works just fine in virtual console. Sure I could just use these and forget about this matter, but I don't think a workaround this would be too complex. I'm just missing something.

I'm posting a custom.kbd with line for keycode 100 already modified. I saved default keymap with kbdcontrol -d > default.kbd but it's exactly the same, except for reading fkey58 where I put fkey65:

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    185    '!'    nop    nop     O
  003   '2'    '@'    nul    nul    178    '@'    nul    nul     O
  004   '3'    '#'    nop    nop    179    '#'    nop    nop     O
  005   '4'    '$'    nop    nop    163    '$'    nop    nop     O
  006   '5'    '%'    nop    nop    162    '%'    nop    nop     O
  007   '6'    duml   rs     rs     172    duml   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    167    '+'    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   dacu   dgra   nop    nop    dacu   dgra   nop    nop     O
  027   '['    '{'    esc    esc    170    '{'    esc    esc     O
  028   cr     cr     nl     nl     cr     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   231    199    nop    nop    231    199    nop    nop     C
  040   dtil   dcir   nop    nop    dtil   dcir   nop    nop     O
  041   '''    '"'    nop    nop    '''    '"'    nop    nop     O
  042   lshift lshift lshift lshift lshift lshift lshift lshift  O
  043   ']'    '}'    gs     gs     186    '}'    gs     gs      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    ';'    ':'    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 '7'    '7'    '7'    '7'    '7'    '7'    '7'     N
  072   fkey50 '8'    '8'    '8'    '8'    '8'    '8'    '8'     N
  073   fkey51 '9'    '9'    '9'    '9'    '9'    '9'    '9'     N
  074   fkey52 '-'    '-'    '-'    '-'    '-'    '-'    '-'     N
  075   fkey53 '4'    '4'    '4'    '4'    '4'    '4'    '4'     N
  076   fkey54 '5'    '5'    '5'    '5'    '5'    '5'    '5'     N
  077   fkey55 '6'    '6'    '6'    '6'    '6'    '6'    '6'     N
  078   fkey56 '+'    '+'    '+'    '+'    '+'    '+'    '+'     N
  079   fkey57 '1'    '1'    '1'    '1'    '1'    '1'    '1'     N
  080   fkey58 '2'    '2'    '2'    '2'    '2'    '2'    '2'     N
  081   fkey59 '3'    '3'    '3'    '3'    '3'    '3'    '3'     N
  082   fkey60 '0'    '0'    '0'    '0'    '0'    '0'    '0'     N
  083   del    ','    ','    ','    ','    ','    boot   boot    N
  084   nop    nop    nop    nop    nop    nop    nop    nop     O
  085   nop    nop    nop    nop    nop    nop    nop    nop     O
  086   '\'    '|'    fs     fs     '\'    '|'    fs     fs      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 fkey49 fkey49 fkey49 fkey49 fkey49 fkey49 fkey49  O
  095   fkey50 fkey50 fkey50 fkey50 fkey50 fkey50 fkey50 fkey50  O
  096   fkey51 fkey51 fkey51 fkey51 fkey51 fkey51 fkey51 fkey51  O
  097   fkey53 fkey53 fkey53 fkey53 fkey53 fkey53 fkey53 fkey53  O
  098   fkey55 fkey55 fkey55 fkey55 fkey55 fkey55 fkey55 fkey55  O
  099   fkey57 fkey57 fkey57 fkey57 fkey57 fkey57 fkey57 fkey57  O
  100   fkey58 fkey58 fkey65 fkey58 fkey58 fkey58 fkey58 fkey58  O
  101   fkey59 fkey59 fkey59 fkey59 fkey59 fkey59 fkey59 fkey59  O
  102   fkey60 paste  fkey60 fkey60 fkey60 fkey60 fkey60 fkey60  O
  103   fkey61 fkey61 fkey61 fkey61 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
  109   nop    nop    nop    nop    nop    nop    nop    nop     O
  110   nop    nop    nop    nop    nop    nop    nop    nop     O
  111   nop    nop    nop    nop    nop    nop    nop    nop     O
  112   nop    nop    nop    nop    nop    nop    nop    nop     O
  113   nop    nop    nop    nop    nop    nop    nop    nop     O
  114   nop    nop    nop    nop    nop    nop    nop    nop     O
  115   '/'    '?'    nop    nop    176    '?'    nop    nop     O
  116   nop    nop    nop    nop    nop    nop    nop    nop     O
  117   nop    nop    nop    nop    nop    nop    nop    nop     O
  118   nop    nop    nop    nop    nop    nop    nop    nop     O
  119   nop    nop    nop    nop    nop    nop    nop    nop     O
  120   nop    nop    nop    nop    nop    nop    nop    nop     O
  121   nop    nop    nop    nop    nop    nop    nop    nop     O
  122   nop    nop    nop    nop    nop    nop    nop    nop     O
  123   nop    nop    nop    nop    nop    nop    nop    nop     O
  124   nop    nop    nop    nop    nop    nop    nop    nop     O
  125   nop    nop    nop    nop    nop    nop    nop    nop     O
  126   '.'    '.'    '.'    '.'    '.'    '.'    '.'    '.'     N

  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 )

Many thanks in advance. Any help is appreciated.
 
I have further considerations to add:
  • BSD showkey differs from its Linux version and shows the raw value returned by a key press, like cat, and not the actual keycode;
  • X and virtual console probably don't share the same scancodes so xev is no longer an option. I'm looking for alternatives;
  • I tried kbdcontrol(1) kbdcontrol -f 10 "telnet myhost" example, to no avail. I tried hitting each of my keyboard keys, randomly, but never got the error message for telnet-ing invalid hostname. I tested keycode 68 according to xev (F2) as well but failed, as expected for I've already mentioned they're not the same;
  • kbdmap(5) says:
    Code:
    You can uset the -f option of the kbdcontrol(1) utility to assign arbitrary strings to function keys.
    Which pretty much solves the problem if control chars (ESC) are allowed on string, or if it's read as a command and used for runnning e.g. echo or printf

What I still don't get is why kbdcontrol(1) example didn't work. I'll try changing an obvious key like 'a' or 'b' to print fkey10 as a symbol just to make it sure.
 
The example with .inputrc only work, if you put
Code:
export INPUTRC=~/.inputrc
in .bashrc.
I have this line in $HOME/.profile.

This thread solved the issue: Thread 57444
  • Fetch base if you don't have /usr/src;
  • Check diff on this post. Six source files are to be "patched";
  • There is a line which must be fixed:
    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 = ((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) &&
    [HIGHLIGHT] +    !( ((key->spcl & (0x80 >> i)) && [NOPARSE](key->map[i] == RBT)) [/NOPARSE] || [/HIGHLIGHT]
    +    ((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/kbd/kbd.c
    [*]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};
  • Apply all changes as indicated by (fixed as shown above) diff;
  • # cd /usr/src/usr.sbin/kbdcontrol/ && make all install to rebuild kbdcontrol(5);
  • Rebuild and reinstall GENERIC then reboot:
    Code:
    # cd /usr/src/
    # make buildkernel KERNCONF=GENERIC
    # make installkernel KERNCONF=GENERIC
    # reboot now
  • $ kbdcontrol -d > custom.kbd or just make a local copy of /usr/share/vt/keymaps/your_default_keymap.iso.kbd;
  • $ sudo pkg install misc/kbdscan or build it from misc/kbdscan ports;
  • $ kbdscan to get the Left/Right arrow keys scancodes then check their corresponding entries in custom.kbd;
  • Change fourth column to "fkey78" for the Left arrow key. Do the same for the Right arrow key using "fkey79";
  • $ kbdcontrol -l custom.kbd to load your customized keymap;
  • If necessary, $ kbdcontrol -F will load default function keys;
Done.
 
Back
Top