Vladimir Sedach

Have Emacs - Will Hack

May 28, 2018

Lisp Machine-style keyboard layout for PC keyboards in the OpenBSD console

OpenBSD includes wsconsctl, a very well thought out utility for configuring the console. Using wsconsctl to change the console keyboard layout to a Lisp Machine style is straightforward, and a good complement to using the layout in X11.

wsconsctl keyboard.map prints out the current keyboard map. wsconsctl configuration changes can be recorded in /etc/wsconsctl.conf. Here is what /etc/wsconsctl.conf looks like on the system I am typing this on:

keyboard.map+="keycode 58 = Delete"
keyboard.map+="keycode 219 = Cmd2 Alt_L"
keyboard.map+="keycode 56 = Cmd1 Control_L"
keyboard.map+="keycode 184 = Cmd1 Control_R"
keyboard.map+="keycode 221 = Cmd2 Alt_R"
keyboard.map+="keycode 10 = 9 bracketleft"
keyboard.map+="keycode 11 = 0 bracketright"
keyboard.map+="keycode 26 = parenleft braceleft"
keyboard.map+="keycode 27 = parenright braceright"

On PCs, the OpenBSD console partially emulates a VT100 terminal. The Meta key is handled by terminals by either setting the 8th bit of the key code, or sending an escape code prefix. The OpenBSD console does not send 8 bit key codes; the keyboard.encoding=us.metaesc option sets Alt to send the Meta modifier escape sequence. It is possible to use other escape sequences to provide the Super and Hyper modifiers in terminal emulators, although neither wscons nor GNU Emacs currently come with support for this.

keyboard.bell.volume=0 mutes the PC speaker.

By default keyboard.map changes are applied to /dev/wskbd0. If your system chipset provides a PS/2 keyboard port and you are using a USB keyboard, the USB keyboard will show up as /dev/wskbd1 and the PS/2 interface will be at /dev/wskbd0. The keyboard device can be specified explicitly with the -f flag:

-f /dev/wskbd1 keyboard.encoding=us.metaesc
-f /dev/wskbd1 keyboard.map+="keycode 58 = Delete"
-f /dev/wskbd1 keyboard.map+="keycode 219 = Cmd2 Alt_L"

The keyboard configuration will be reset every time you unplug the USB keyboard, and can be applied again by doing the same thing as the wsconsctl_conf function from /etc/rc:

stripcom /etc/wsconsctl.conf |
while read _line; do
	eval "wsconsctl $_line"