FreeBSD Console Keyboard Maps and Scancodes

I sometimes work directly in the FreeBSD console. It's important to me that I get the same keyboard mapping in the console that I live with everywhere else, such as in X.

Many moons ago, possibly in 2002, I defined a console keymap that gives me the standard Swedish keyboard, but with a twist: AltGr + ÅÄÖ gives me ][\ and AltGr + åäö gives me }{|. People who grew up with 7 bit Swedish ASCII terminals will understand the logic behind this. Besides, the positions for these characters is much better than on a regular Swedish keyboard. As you might guess, it's important for a programmer to reach these characters easily.

This mapping also changes virtual consoles directly when hitting the function keys unmodified.

You can find the keymap here:

http://hack.org/mc/files/freebsd-sw.kbd

You load it with

% kbdcontrol -l freebsd-sw.kbd

in a console of your choice.

My keyboard of choice these days is an original Happy Hacking Keyboard. It's a little different, so I have defined new keyboard mappings for use with the HHKB in the FreeBSD console.

Swedish mapping equivalent to the above:

http://hack.org/mc/files/freebsd-hhkb-se.kbd

The HHKB doesn't have as much keys on some rows as a standard Swedish keyboard, so there are some exceptions:

Here's my straight US mapping:

http://hack.org/mc/files/freebsd-hhkb-us.kbd

but with Swedish characters on Alt + []}{|.

Here's a similar US mapping, but with Swedish characters by default on []}{|:

http://hack.org/mc/files/freebsd-hhkb-us-se.kbd

Scancodes

The FreeBSD console keymap files use the keyboard scancodes to identify keys pressed. It may be hard to know what scancode a certain key generates.

My keymaps above were usually defined by simply editing existing keyfiles, but sometimes you find a keyboard which doesn't give anything by pressing a key. That is, you need to find the scancode of the key.

Unfortunately, there is no standard tool to get the scancode in FreeBSD.

I ended up writing one. It's somewhat of a hack but should work:

http://hack.org/mc/hacks/kbdscan/

It's also available in FreeBSD ports as misc/kbdscan. I would have chosen the sysutils category but I didn't add it. The code is released under the ISC license.

The program sets the terminal in raw mode, sets the FreeBSD console keyboard to give untranslated scancodes and shows what scancodes are pressed and released. Five seconds of inactivity resets the terminal back to the original mode and quits the program.

Thanks to Ivan Pascal who made me realize what IOCTLs to use.