Simple patch for wscons keyboard in NetBSD. After patching and building mlterm (cd mlterm-3.8.8; patch -p1 < mlterm-wscons-keyboard.diff) all you need is a valid keyboard map for wscons (see /etc/wscons.conf file). Sample definitinion: keycode 4 = a A aogonek Aogonek keycode 8 = e E eogonek Eogonek where 'aogonek' etc. are defined in /usr/include/dev/wscons/wsksymdef.h --- mlterm-3.8.8/uitoolkit/fb/ui_window.c.orig 2019-03-31 15:10:47.000000000 +0200 +++ mlterm-3.8.8/uitoolkit/fb/ui_window.c 2019-05-02 13:30:44.160503028 +0200 @@ -1898,7 +1898,7 @@ size_t ui_window_get_str(ui_window_t *win, u_char *seq, size_t seq_len, ef_parser_t **parser, KeySym *keysym, XKeyEvent *event) { - u_char ch; + u_int ch; if (seq_len == 0) { return 0; @@ -1933,7 +1933,7 @@ } #endif - if ((*keysym = event->ksym) >= 0x100) { + if ((*keysym = event->ksym) >= 0x7f) { switch (*keysym) { case XK_KP_Multiply: ch = '*'; @@ -1950,7 +1950,7 @@ case XK_KP_Divide: ch = '/'; break; - + default: if (win->disp->display->lock_state & NLKED) { switch (*keysym) { @@ -1993,6 +1993,25 @@ *keysym = ch; } else { + /* taken from FreeBSD: sys/kern/subr_terminal.c: + * http://fxr.watson.org/fxr/source/kern/subr_terminal.c?v=FREEBSD-12-STABLE#L283 + * algorithm was created for UTF-32, but below 0x10000 + * UTF-16 and UTF-32 are the same + * + * surrogate pairs - 0xd800 to 0xdfff aren't supported + * there is no printable keys in NetBSD over 0xdfff at this moment + */ + if (ch < 0x800) { + seq[0] = 0xc0 | (ch >> 6); + seq[1] = 0x80 | (ch & 0x3f); + return 2; + } else if (ch < 0xd800) { + seq[0] = 0xe0 | (ch >> 12); + seq[1] = 0x80 | ((ch >> 6) & 0x3f); + seq[2] = 0x80 | (ch & 0x3f); + return 3; + }; + return 0; } }